Passing URI Segments to CI Controller Methods

Most of this information is copied from the UG.

Passing Parameters to your Controller’s Method Using the URI in your Request could have been the title of this post.

If your URI contains more than two segments they will be passed to your function (controller method) as parameters.

For example, lets say you have a URI like this:

example.com/index.php/products/shoes/sandals/123

Your function will be passed URI segments 3 and 4 ("sandals" and "123"):

<?php
class Products extends CI_Controller {

    public function shoes($sandals, $id)
    {
        echo $sandals;
        echo $id;
    }
}
?>

Important:
If you are using the URI Routing feature, the segments passed to your function will be the re-routed ones.

Advertisements

About samehramzylabib

See About on https://samehramzylabib.wordpress.com
This entry was posted in CodeIgniter. Bookmark the permalink.

Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s