The method requestAction are used in cake php for calls a controller’s
action from any location and returns data from the action.
Example :
Example :
// Controller/CommentsController.php
class CommentsController extends AppController {
public function latest() {
if (empty($this->request->params['requested'])) {
throw new ForbiddenException();
}
return $this->Comment->find('all', array('order' => 'Comment.created DESC', 'limit' => 10));
}
}
// View/Elements/latest_comments.ctp
$comments = $this->requestAction('/comments/latest');
foreach ($comments as $comment) {
echo $comment['Comment']['title'];
}
No comments:
Post a Comment