CodeIgniter Forums
how make url like this articles/2008/08/18/america/page.php - 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: how make url like this articles/2008/08/18/america/page.php (/showthread.php?tid=10916)



how make url like this articles/2008/08/18/america/page.php - El Forum - 08-18-2008

[eluser]Asinox[/eluser]
hi, i want to know how ill make url like this:

how make url like this articles/2008/08/18/america/page.php

thanks


how make url like this articles/2008/08/18/america/page.php - El Forum - 08-19-2008

[eluser]gon[/eluser]
First, name your controller articles.

Then you probably will notice that you can't skip the method name if you want to add parameters. For example, you must use

/articles/index/2008/08/18/america

To avoid this you can write a route:

$routes['articles/(.+?)'] = "articles/index/$1";

So index method will be executed.

Another technique is putting a _remap($action) function in the controller. All calls will execute this function, passing the method as an $action argument. In this case $action would be "2008", so you would just ignore it, and access the segments array to get the params.

In both cases you can add some checkins on parameters:
Year, month, day to be numeric, zone must be one of the zones present in the DB, etc.
Then if any of these conditions fail, you do a show_404();


To get the params you can access $this->uri->segment_array(), although probably parameters will be passed to index function as arguments. Not sure on this. If you do this and some of the parameters are optional, don't forget to initialize them at index.

Code:
function index($year = null, $month = null, $day = null, $zone = null) {


Why do you want page.php to appear?

Most people prefer clean URLS. If you need it to appear, you can consider it another argument, check if it is passed, and do a show_404() if it is not present.


how make url like this articles/2008/08/18/america/page.php - El Forum - 08-19-2008

[eluser]Asinox[/eluser]
Thanks Gon