There are different type of methods that we can use in cakePHP to add functionality.
1. constructClasses()- This method load the model required by the controller. This can be used while in the command line prompt.
2.referrer(mixed $default = null, boolean $local = false)- It returns the referring url.It can be used to supply a default URL to use if HTTP_REFERER cannot be read from headers
public function delete($id) {
// delete code goes here, and then...
if ($this->referer() != '/') {
return $this->redirect($this->referer());
}
return $this->redirect(array('action' => 'index'));
}
3. disableCache()- This is mostly used to tell the user’s browser not to cache the results of the current request.
4.postCondition()- It's used to set the POSTed model data into a set of find condition for a model. It is used where we want to search something
5.paginate()- It used for paginate the result fetched by the model. We can specify the size and give various condition to paginate the data fetched by the model on the ctp.
6.requestAction()- This function calls a controller’s action from any location and returns data from the action
public function latest() {
if (empty($this->request->params['requested'])) {
throw new ForbiddenException();
}
return $this->Comment->find(
'all',
array('order' => 'Comment.created DESC', 'limit' => 10)
);
}
0 Comment(s)