Sunday, November 30, 2014

Re: Is there a way to put request variables in paginate class property?

You're on the right track with the second code bit.. but i'd abstract that assignment into its own controller method and then call that from whatever action you need it set -- or if the request params are avaialble early enough (i don't know -- i don't do automagical platforms these days -- I'm on ZF2) then call it on __invoke or __constructor or something.

On Sun, Nov 30, 2014 at 4:23 PM, Sam Clauw <info@bellewaerdefun.be> wrote:
I want to sort an array of data in my index action and one condition depends on the id given by the request object (attraction_id). Is there a way to set up the paginate component as a controller class method (see under)?

<?php

class AttractionCommentsController extends CoasterCmsAppController
{
   
public $paginate = array(
       
'AttractionComment' => array(
           
'conditions' => array(
               
'Attraction.id' => $this->request->params['named']['attraction_id'],
               
'AttractionComment.deleted' => null
           
),
           
'order' => array(
               
'AttractionComment.created' => 'DESC',
               
'AttractionComment.id' => 'ASC'
           
),
           
'limit' => 15
       
)
   
);
   
   
public function index()
   
{
        $this
->Paginator->settings = $this->paginate;
       
        $comments
= $this->Paginator->paginate('AttractionComment');
       
        $this
->set('comments', $comments);
   
}

?>


The above code can't handle the request variable ($this->request->params['named']['attraction_id']) within the class method.
So... is there a solution for this or is it required to drop the class property and do something like this:

<?php

class AttractionCommentsController extends CoasterCmsAppController
{
   
public function index()
   
{

        $this
->Paginator->settings = array(
           
'AttractionComment' => array(
               
'conditions' => array(
                   
'Attraction.id' => $this->request->params['named']['attraction_id'],
                   
'AttractionComment.deleted' => null
               
),
               
'order' => array(
                   
'AttractionComment.created' => 'DESC',
                   
'AttractionComment.id' => 'ASC'
               
),
               
'limit' => 15
           
)
       
);        
        $comments
= $this->Paginator->paginate('AttractionComment');
       
        $this
->set('comments', $comments);
   
}

?>

Thx 4 helping!

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: