Control Display Fields
In our previous example, say, I want to display only the comments title, body, and created fields. So, I will add the following lines in comments_controller.php (found under '/app/controllers') just below
var $scaffold;
statement.
function beforeRender() {
if($this->action === 'index'){
$this->set( 'scaffoldFields', array( 'title', 'body', 'created' ) );
}
}
Note 'beforeRender()' is a CakePHP callback. It gets executed before the actual controller action. This helps you to add some more logic in your controller. There are three controller callback methods in common use: beforeFilter(), beforeRender(), afterFilter()
And here is that much desired screenshot:
For a more detailed discussion, please go through the book.
No comments:
Post a Comment