Cakephp Classroom image

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

Finally, if the last parameter is set to true, and the $op parameter is an array, fields not included in $op
will not be included in the returned conditions.
Controller::paginate()
This method is used for paginating results fetched by your models. You can specify page sizes, model
find conditions and more. See the pagination section for more details on how to use paginate.
Controller::requestAction(string $url, array $options)
This function calls a controller’s action from any location and returns data from the action. The $url
passed is a CakePHP-relative URL (/controllername/actionname/params). To pass extra data to the
receiving controller action add to the $options array.
Note: You can use requestAction() to retrieve a fully rendered view by passing ‘return’ in the
options: requestAction($url, array(’return’));. It is important to note that making
a requestAction using ‘return’ from a controller method can cause script and css tags to not work
correctly.
Warning: If used without caching requestAction can lead to poor performance. It is rarely
appropriate to use in a controller or model.
requestAction is best used in conjunction with (cached) elements – as a way to fetch data for an
element before rendering. Let’s use the example of putting a “latest comments” element in the layout.
First we need to create a controller function that will return the data:
// 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’ }
}
You should always include checks to make sure your requestAction methods are actually originating
from requestAction. Failing to do so will allow requestAction methods to be directly accessible
from a URL, which is generally undesirable.
If we now create a simple element to call that function:
// View/Elements/latest_comments.ctp
$comments = $this->requestAction(’/comments/latest’);
foreach ($comments as $comment) {
echo $comment[’Comment’][’title’];
}
We can then place that element anywhere to get the output using:
echo $this->element(’latest_comments’);

 
 
 

osdyui

Skills    Cakephp

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

  Students (0)