Mario Catena
Mario Catena

Reputation: 635

CodeIgniter route and pass values to method

there is something I’m not getting about use route to call a method passing three values. I have a controller with the following method inside

public function view_day($year, $month, $day)
{
    $data['year'] = $year;
    $data['month'] = $month;
    $data['day'] = $day;

    $this->load->view('calendar/view_day', $data);
}

and a page within my views folder with the follows

<? 
    echo $this->uri->segment(5).'<p>'; 
    echo $day;
?>

finally, within my routes file I have the line below

$route['calendar/date/:num/:num/:num'] = "calendar/view_day/$1/$2/$3";

What I supposed to do is route an url like

http://www.mydomain.com/index.php/calendar/date/2012/06/10

to my calendar controller passing three values (2012, 06 and 10) to my view_day method. Then, collect these three values and pass them to my final page in order to use $day, $month and $year inside my presentation page. Now, running the url above the result is

10 (returned by the row -> echo $this->uri->segment(5).’‘;) $3 (returned by the row -> echo $day;)

Basically, what I’m not getting is way the variable $day inside my presentation page is not getting any value as passed inside the url but returns the same text ($3) I have wrote in my route statement.

Thanks

Upvotes: 3

Views: 6706

Answers (1)

Broncha
Broncha

Reputation: 3794

You should define your route like this

$route['calendar/date/(:num)/(:num)/(:num)'] = "calendar/view_day/$1/$2/$3";

Upvotes: 6

Related Questions