• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how make url like this articles/2008/08/18/america/page.php

hi, i want to know how ill make url like this:

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


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


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.

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.

Thanks Gon

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.