Breaking News
You are here : Home / Web development / CakePHP / Using CakePHP containable Behavior with Paginator

Using CakePHP containable Behavior with Paginator

 CakePHP containable Behavior with Paginator:

Hola Guys ! CakePHP’s  containable Behaviour is very useful and robust way to achieve your programming goals in cakePHP. Some time we dont need recursive data as it produces lot of useless data and slows down the speed of our project.So to overcome this issue we have a cakephp containable behavior. In this post i’ll focus on how we use cakephp Containable Behavior with the Paginator . As other ways of using Containable behavior are well mentioned in .

Using containable Behavior with Paginator:

So when ever we wana use cakephp containable Behavior we need to include in it our model or just include it in our AppModel ,So it will automatically included in all our Models.Here is how we do it

Including cakephp Containable Behavior in AppModel:


class AppModel extends Model{
[highlight bg=”#DDFF99″ color=”#000000″]var $actsAs = array(‘Containable’);[/highlight]


Using containable Behavior with Paginator in Our Controller:

SO now we ave inluded Cakephp Containable behavior in our AppModel , Now we See how to use it in our Contoller,as i said before we look how to use  Containable behavior with the Paginator in cakephp .So we see how to do it:

Using Cakephp Containable behavior with paginator:

Now inside our controller we’ll  use cakephp Containable Behavior with the paginator and we gonna paginate results with the help of containable behavior.Lets see how we gonna do it:

Using Containable behavior with paginator in CakePHP


“fields”=>array(“”,””)  //will fetch user name and id only






//the above code will fetch UserBiodata table and also the UserEmployer’s name field.

//The UserBiodata and UserEmployer must have a relation to perform this kind of fetch


Now that was easy.And also produces clean data.I thing more is that if  you are using Containable with paginator You need not to use recursive.So while using cakephp containable behavior in paginator we’ll not use  the recursive.

Another Important issue is that the limit of paginator will not work using the above containable with the Paginator in cakephp .So here is a fix to the paginator limit.Just add another line like below.

Using Containable behavior with paginator in CakePHP


//Using limit in paginator with the containable


That was all i guess for the cakephp’s Containable behavior with the paginator.So thankx for visiting and reading the content written by us.

Hope you liked our content and Tutorial might be helpful.Do not forget to share if it was helful



Tags : , ,

1 Reply

  1. Rashmil says:

    I am new to cakephp and want to create my own plugin. Could u please help me out with it.

Leave a Reply

Want to join the discussion ? Feel Free to contribute !