I basically want to be able to pass a value through a function before sending the results to my view…
public function listing() {
$this->set('posts', $this->paginate('Post'));
}
So I want something in there to say, for example:
foreach($posts as $post){
$post["Post"]["timestamp"] = $this->timeago($post["Post"]["timestamp"]);
}
And then I want to paginate the results with this field, and set ‘posts’ as the overall array that I send to the view – having updated the timestamp with the ‘timeago’ function. What is the best way of doing this?
you may consider to implement those method in model behavior afterFind().
for more information see: http://book.cakephp.org/2.0/en/models/callback-methods.html