question concerning url parameters |
[eluser]plainas[/eluser]
Ok... so I want to have an url structure like this: http://example.com/myapp/food/list/fruit That's fine, but let's say that I got so much fruit that i need to use pagination. I can use for example CI pagination class and work out a url like this: http://example.com/myapp/food/list/fruit/page/3 In this case the third page would show. One might think that there is no problem with this. But there is a problem, an url like the last one, with the meaningful content in the end, is a lot more search engine friendly. I don't mind having links like: http://example.com/myapp/food/list/fruit/page/2 http://example.com/myapp/food/list/fruit/page/3 http://example.com/myapp/food/list/fruit/page/4 ... but there's a quite good SEO advantage in using a simpler url for the first page: http://example.com/myapp/food/list/fruit instead of something like this: http://example.com/myapp/food/list/fruit/page/1 Problem is: if a controller function definition as the page number as a parameter, then it will throw an error if it's not present. How can one make an url parameter optional?
[eluser]Colin Williams[/eluser]
Code: $page_num = $this->uri->segment(6, 1);
[eluser]ontguy[/eluser]
You could set a default parameter for your function. Code: function list ($type, $page = 1)
[eluser]Tom Glover[/eluser]
[quote author="ontguy" date="1218608298"]You could set a default parameter for your function. Code: function list ($type, $page = 1) this is probably the best way to do it, because you can still reorder your url's at a later date with out breaking the rest of your code.
[eluser]plainas[/eluser]
Dummy me, this is basinc PHP. Thank you for the replies. |
Welcome Guest, Not a member yet? Register Sign In |