Welcome Guest, Not a member yet? Register   Sign In
Can I Route YYYY/MM/DD URL Segments to a Controller?
#1

[eluser]kirkaracha[/eluser]
I'm trying to use routes to have a timeline controller handle URLs like this: example.com/2011/04/15

I tried these routes, but they aren't working (I get a 404):
Code:
$route['(:num)/(:num)/(:num)'] = 'timeline/$1/$2/$3'; //  year, month, and day
$route['(:num)/(:num)'] = 'timeline/$1/$2'; // year and month
$route['(:num)'] = 'timeline/$1/'; // year only

What am I missing?
#2

[eluser]guidorossi[/eluser]
I think that's because the "2011" function doesn't exists under the timeline controller...

It should be:

Code:
$route['(:num)/(:num)/(:num)'] = 'timeline/foo/$1/$2/$3'; //  year, month, and day
$route['(:num)/(:num)'] = 'timeline/foo/$1/$2'; // year and month
$route['(:num)'] = 'timeline/foo/$1/'; // year only

and the controller like:

Code:
class Timeline extends CI_Controller {

    function __construct()
    {
        parent::__construct();
    }

    function foo()
    {
      //some code...
    }
}
#3

[eluser]kirkaracha[/eluser]
This worked, thanks!

Routes:
Code:
$route['(:num)/(:num)/(:num)'] = 'timeline/day/$1/$2/$3';
$route['(:num)/(:num)'] = 'timeline/month/$1/$2';
$route['(:num)'] = 'timeline/year/$1/';

Controller:

Code:
public function year() {
    $data = array(
        'message_text' => 'year'
    );
    $this->layouts->view('shared/display_messages',$data);
} // year

public function month() {
    $data = array(
        'message_text' => 'month'
    );
    $this->layouts->view('shared/display_messages',$data);
} // month

public function day() {
    $data = array(
        'message_text' => 'day'
    );
    $this->layouts->view('shared/display_messages',$data);
} // day




Theme © iAndrew 2016 - Forum software by © MyBB