CodeIgniter Forums
question concerning url parameters - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: question concerning url parameters (/showthread.php?tid=10794)



question concerning url parameters - El Forum - 08-12-2008

[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?


question concerning url parameters - El Forum - 08-12-2008

[eluser]Colin Williams[/eluser]
Code:
$page_num = $this->uri->segment(6, 1);
// Returns 1 if there is no 6th segment



question concerning url parameters - El Forum - 08-12-2008

[eluser]ontguy[/eluser]
You could set a default parameter for your function.

Code:
function list ($type, $page = 1)



question concerning url parameters - El Forum - 08-13-2008

[eluser]Tom Glover[/eluser]
[quote author="ontguy" date="1218608298"]You could set a default parameter for your function.

Code:
function list ($type, $page = 1)
[/quote]

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.


question concerning url parameters - El Forum - 08-13-2008

[eluser]plainas[/eluser]
Dummy me, this is basinc PHP.
Thank you for the replies.