URI Segments |
[eluser]hykoh[/eluser]
Sorry, but I cant find any useful explaination at the forum / wiki about this topic. I beginning with an example: Code: http://www.example.com/index.php?page=products&category=1&supplier=5 How can I handle such a link with the CI URI segment ? If i try Code: example.com/index.php/products/category/1/supplier/5 i dont know how to access the values like in the first example ($_GET['category'], $_GET['supplier'] etc.) I cant find out how much parameters given and i cant choose a specified segment thrue the name, right ? So what else can i do ? The segments are dynamically doing their job as filters .. there could be even more then this two. Thanks for help
[eluser]wiZe[/eluser]
if you want to pass data via GET you have to enable query strings in the system/application/config/config.php. otherwise read the userguide article about how the urls in CI work: click here
[eluser]xwero[/eluser]
You can get an associative array of the segments using the uri->uri_to_assoc(). The function has one parameter where you can define the offset if it isn't 3. so in your case Code: print_r($this->uri->uri_to_assoc(2));
[eluser]hykoh[/eluser]
ok works fine :-) Thanks alot for this nice and fast support here
[eluser]Dready[/eluser]
Hello, as you noticed, in CI your pass parameters just like URI segments (/some/thing) , instead of the classic varname=value&varname2=value2. The controller function that is called should have parameters for you to get back those variables. In your example, you have to create a controller, something like that : Code: class products extends controller { And then call it with the URL : Code: example.com/index.php/products/show/1/5 More info on controllers in the doc
[eluser]xwero[/eluser]
Dready i think the way you build your url shouldn't be forced. If you like the key/value pair way why should you have to do it with fixed segments. The key/value pairs give you more flexibility.
[eluser]hykoh[/eluser]
xwero offers me the best solution i wanted :-) my solution now: products_controller.php: Code: class Products extends Controller { product_model: Code: class Products_model extends Model { Works fine for me But maybe there's something to optimise ? Greets |
Welcome Guest, Not a member yet? Register Sign In |