I am trying to create a controller that acts similar to that of which
you find commonly on blogs. I want the user to be able to type
http://www.example.com/2008/05/20/, http://www.example.com/2008/05/,
and http://www.example.com/2008/ to be directed to an archive for the
current day, month, and year respectively. So far I have a Posts
controller with the following:
<code>
<?php
class PostsController extends AppController {
var $name = 'Posts';
function index() {
$year = $this->params['year'];
$month = $this->params['month'];
$day = $this->params['day'];
// How do I redirect to the appropriate view?
}
function p_year($year) {
$posts = $this->Post->findAll(
"YEAR(published)=$year"
);
$this->set('posts', $posts);
}
function p_year_month($year, $month) {
$posts = $this->Post->findAll(
"YEAR(published)=$year AND MONTH(published)=$month"
);
$this->set('posts', $posts);
}
function p_year_month_day($year, $month, $day) {
$posts = $this->Post->findAll(
"YEAR(published)=$year AND MONTH(published)=$month AND
DAY(published)=$day"
);
$this->set('posts', $posts);
}
}
?>
</code>
And I have my routing configuration set up as follows:
<code>
Router::connect('/:controller/:year/:month/:day', array(
'action' => 'index',
'month' => null,
'day' => null
), array(
'year' => '[12][0-9]{3}',
'month' => '(0[1-9]|1[012])',
'day' => '(0[1-9]|[12][0-9]|3[01])'
));
</code>
How do I make it such that each different variation of the date gets
redirected to the appropriate view? Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---