Welcome Guest, Not a member yet? Register   Sign In
how make url like this articles/2008/08/18/america/page.php
#2

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


Messages In This Thread
how make url like this articles/2008/08/18/america/page.php - by El Forum - 08-19-2008, 02:40 AM



Theme © iAndrew 2016 - Forum software by © MyBB