Cakephp Classroom image

osdyui
 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11|Last
Lessons:-Controllers

Callbacks
In addition to the Request Life-cycle callbacks. CakePHP also supports callbacks related to scaffolding.
Controller::beforeScaffold($method)
$method name of method called example index, edit, etc.
Controller::afterScaffoldSave($method)
$method name of method called either edit or update.
Controller::afterScaffoldSaveError($method)
$method name of method called either edit or update.
Controller::scaffoldError($method)
$method name of method called example index, edit, etc.
Other Useful Methods
Controller::constructClasses()
This method loads the models required by the controller. This loading process is done by CakePHP
normally, but this method is handy to have when accessing controllers from a different perspective. If
you need CakePHP in a command-line script or some other outside use, constructClasses() may come
in handy.
Controller::referer(mixed $default = null, boolean $local = false)
Returns the referring URL for the current request. Parameter $default can be used to supply a
default URL to use if HTTP_REFERER cannot be read from headers. So, instead of doing this:
class UserController extends AppController {
public function delete($id) {
// delete code goes here, and then...
if ($this->referer() != ’/’) {
$this->redirect($this->referer());
} else {
$this->redirect(array(’action’ => ’index’));
}
}
}
you can do this:
class UserController extends AppController {
public function delete($id) {
// delete code goes here, and then...
$this->redirect($this->referer(array(’action’ => ’index’)));
}
}
If $default is not set, the function defaults to the root of your domain - ‘/’.
Parameter $local if set to true, restricts referring URLs to local server.Controller::disableCache()
Used to tell the user’s browser not to cache the results of the current request. This is different than
view caching, covered in a later chapter.
The headers sent to this effect are:
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Last-Modified: [current datetime] GMT
Cache-Control: no-store, no-cache, must-revalidate
Cache-Control: post-check=0, pre-check=0
Pragma: no-cache
Controller::postConditions(array $data, mixed $op, string $bool, boolean $exclusive)
Use this method to turn a set of POSTed model data (from HtmlHelper-compatible inputs) into a set
of find conditions for a model. This function offers a quick shortcut on building search logic. For
example, an administrative user may want to be able to search orders in order to know which items
need to be shipped. You can use CakePHP’s FormHelper and HtmlHelper to create a quick form
based on the Order model. Then a controller action can use the data posted from that form to craft
find conditions:
public function index() {
$conditions = $this->postConditions($this->request->data);
$orders = $this->Order->find(’all’, compact(’conditions’));
$this->set(’orders’, $orders);
}
If $this->request->data[’Order’][’destination’] equals “Old Towne Bakery”,
postConditions converts that condition to an array compatible for use in a Model->find() method.
In this case, array(’Order.destination’ => ’Old Towne Bakery’).
If you want to use a different SQL operator between terms, supply them using the second parameter:
/*
Contents of $this->request->data
array(
’Order’ => array(
’num_items’ => ’4’,
’referrer’ => ’Ye Olde’
)
)
*/
// Let’s get orders that have at least 4 items and contain ’Ye Olde’
$conditions = $this->postConditions(
$this->request->data,
array(
’num_items’ => ’>=’,
’referrer’ => ’LIKE’
)
);
$orders = $this->Order->find(’all’, compact(’conditions’));
The third parameter allows you to tell CakePHP what SQL boolean operator to use between the find
conditions. Strings like ‘AND’, ‘OR’ and ‘XOR’ are all valid values.

 
 
 

osdyui

Skills    Cakephp

Qualifications :-
Location :-,,,
Description:-
Explore
 

  Students (0)