Containable with Pagination

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Containable with Pagination

Justin Atack
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Containable with Pagination

Andras Kende

try something like:

class SchedulesController extends AppController {

        public $components = array('Paginator');

        public function show() {

                $this->Paginator->settings = array(
                        'Schedule' => array(
                                'contain' => array(
                                        'Assignment',
                                ),
                                'limit' => 20,
                                'conditions' => array(
                                ),
                                'order' => array(
                                ),
                        )
                );
                $this->set('schedules', $this->Paginator->paginate());
        }


Andras Kende


On Feb 20, 2014, at 3:49 PM, Justin Atack <[hidden email]> 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 [hidden email].
> To post to this group, send email to [hidden email].
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/groups/opt_out.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Containable with Pagination

Justin Atack
In reply to this post by Justin Atack
Haha that works! You're a genius!

Thank you so much.

So is the CakePHP manual incorrect?

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" - <a href="http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html#using-containable-with-pagination" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fbook.cakephp.org%2F2.0%2Fen%2Fcore-libraries%2Fbehaviors%2Fcontainable.html%23using-containable-with-pagination\46sa\75D\46sntz\0751\46usg\75AFQjCNHppcyVh5iQUxsi3HFpVB8NTVPSMQ';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fbook.cakephp.org%2F2.0%2Fen%2Fcore-libraries%2Fbehaviors%2Fcontainable.html%23using-containable-with-pagination\46sa\75D\46sntz\0751\46usg\75AFQjCNHppcyVh5iQUxsi3HFpVB8NTVPSMQ';return true;">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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Containable with Pagination

Andras Kende

You had this incorrectly  :
$this->paginate['contain'] = array(

Manual:
$this->paginate['User'] = array(
        'contain' => array('Profile', 'Account'),
        'order' => 'User.username'
);
$users = $this->paginate('User');

Andras Kende

On Feb 20, 2014, at 10:43 PM, Justin Atack <[hidden email]> wrote:

> Haha that works! You're a genius!
>
> Thank you so much.
>
> So is the CakePHP manual incorrect?
>
> 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 [hidden email].
> To post to this group, send email to [hidden email].
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/groups/opt_out.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Containable with Pagination

Justin Atack
In reply to this post by Justin Atack
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()
);

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

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" - <a href="http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html#using-containable-with-pagination" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fbook.cakephp.org%2F2.0%2Fen%2Fcore-libraries%2Fbehaviors%2Fcontainable.html%23using-containable-with-pagination\46sa\75D\46sntz\0751\46usg\75AFQjCNHppcyVh5iQUxsi3HFpVB8NTVPSMQ';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fbook.cakephp.org%2F2.0%2Fen%2Fcore-libraries%2Fbehaviors%2Fcontainable.html%23using-containable-with-pagination\46sa\75D\46sntz\0751\46usg\75AFQjCNHppcyVh5iQUxsi3HFpVB8NTVPSMQ';return true;">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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Containable with Pagination

Justin Atack
In reply to this post by Justin Atack
Gives me the same error: Notice (8): Indirect modification of overloaded property SchedulesController::$paginate has no effect [APP/Controller/SchedulesController.php, line 35]

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" - <a href="http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html#using-containable-with-pagination" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fbook.cakephp.org%2F2.0%2Fen%2Fcore-libraries%2Fbehaviors%2Fcontainable.html%23using-containable-with-pagination\46sa\75D\46sntz\0751\46usg\75AFQjCNHppcyVh5iQUxsi3HFpVB8NTVPSMQ';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fbook.cakephp.org%2F2.0%2Fen%2Fcore-libraries%2Fbehaviors%2Fcontainable.html%23using-containable-with-pagination\46sa\75D\46sntz\0751\46usg\75AFQjCNHppcyVh5iQUxsi3HFpVB8NTVPSMQ';return true;">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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Containable with Pagination

Andras Kende
In reply to this post by Justin Atack

On Feb 21, 2014, at 1:23 AM, Justin Atack <[hidden email]> 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" - <a href="http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html#using-containable-with-pagination" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fbook.cakephp.org%2F2.0%2Fen%2Fcore-libraries%2Fbehaviors%2Fcontainable.html%23using-containable-with-pagination\46sa\75D\46sntz\0751\46usg\75AFQjCNHppcyVh5iQUxsi3HFpVB8NTVPSMQ';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fbook.cakephp.org%2F2.0%2Fen%2Fcore-libraries%2Fbehaviors%2Fcontainable.html%23using-containable-with-pagination\46sa\75D\46sntz\0751\46usg\75AFQjCNHppcyVh5iQUxsi3HFpVB8NTVPSMQ';return true;">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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.