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 book.cakephp.org .
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:
var $actsAs = array(‘Containable’);
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:
“fields”=>array(“User.id”,”User.name”) //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 limit in paginator with the containable
That was all i guess for the cakephp’s Containable behavior with the paginator.So thankx for visiting designaeon.com 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