The Controller
We find a random record, and then we reuse the current view action and template.
controllers/posts_controller.php
class PostsController extends AppController {
var $name = 'Posts';
function random() {
$random = $this->Post->find('first',array(
'conditions' => array(
'Post.active'=>1,
),
'order' => 'rand()',
));
$this->view($random['Post']['id']);
$this->render('view');
}
}
Nice, buy this kind of method should definitely go to the Model (fat models, skinny…)
nice and clean, thx