On Tue, May 20, 2008 at 7:07 PM, Travis <[EMAIL PROTECTED]> wrote:
>
> 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.
>
> How do I make it such that each different variation of the date gets
> redirected to the appropriate view? Thanks!
Do you actually present this data differently? Because I'd do it like this:
<code>
<?php
class PostsController extends AppController {
var $name = 'Posts';
function index() {
$year = $this->params['year'];
$month = $this->params['month'];
$day = $this->params['day'];
$conditions = "YEAR(published)=$year";
if (!empty($month)) {
$conditions .= " AND MONTH(published)=$month";
}
if (!empty($day)) {
$conditions .= " AND DAY(published)=$day";
}
$posts = $this->Post->findAll($conditions);
$this->set('posts', $posts);
}
}
?>
</code>
I think this simplifies your code and makes it easier to read. :)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---