Friday, February 21, 2014

Re: Containable with Pagination


On Feb 21, 2014, at 1:23 AM, Justin Atack <justinatack@gmail.com> wrote:

Hi Andras,

I'm keen to try and find the error in my code so that I can learn. I have fixed the code so that's its like the manual but it's still not working. I have kept a copy of the working code :)

$this->paginate['Schedule'] = array(
'contain' => array(
'Assignment' => array(
'fields' => array(),
'AssignmentsStudent' => array(
'fields' => array(),
'School' => array('fields' => array('id', 'name')),
'Student' => array(
'fields' => array('id', 'given_name', 'family_name')
)
)
)
),
'fields' => array('id', 'name', 'date'),
'limit' => 20,
'conditions' => array(),
'order' => array()
);


This part is wrong:

$schedules = $this->paginate('Schedule');
$this->set('schedules', $this->Paginator->paginate());

try to change to either :

$this->set('schedules', $this->Paginator->paginate());
or
$this->set('schedules', $this->paginate('Schedule’));


Andras


On Friday, 21 February 2014 10:49:00 UTC+11, Justin Atack wrote:
Hi All,

I'm having a problem getting Containable behaviour working with the Pagination component. I'm following the suggested code in the manual "Using Containable with Pagination" - http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html#using-containable-with-pagination

My code is as follows (SchedulesController.php)

public function show() {

$this->paginate['contain'] = array(
'Assignment' => array(
'AssignmentsStudent' => array(
'School' => array('fields' => array('name')),
'Student' => array('fields' => array('given_name', 'family_name'))
),
'Type' => array('fields' => array('name', 'acronym')),
'fields' => array('theme', 'source')
),
'fields' => array(
'name',
'date'
)
);

$this->set('schedules', $this->Paginator->paginate());
}

However running this code gives me the following error

Notice (8): Indirect modification of overloaded property SchedulesController::$paginate has no effect [APP/Controller/SchedulesController.php, line 35]

I have double checked the I have public $actsAs = array('Containable'); in my Schedule.php model file. The output array doesn't contain any of the deep associations and I guess this is because of what the error says "$paginate has no effect".

I have containable working in some other controllers (not with pagination) so I'm fairly confident that my array nesting is ok.... but I could be wrong.

Any assistance would be welcome!



--
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/groups/opt_out.

No comments: