Thursday, May 23, 2013

CakePHP 2.x Moving Find into Model

I'm trying to achieve the fat model/skinny controller mantra in CakePHP 2.7. In that scenario, the model should control the data, and that means moving the finds out of the controllers and into the models. However, at least with the view and admin_view actions, one needs the data paginated.

The problem starts there. It's easy enough to do a $this->find('all') in the model to get the data, along with any conditions, contains, etc. However that produces an array. Paginator->paginate(), as far as I can tell won't work in the model; it's a component that only works in a controller. Yet, if I take the array produced in the model into the controller and try to pass it on to Paginator->paginate(), it fails because paginate won't accept an array.

In terms of trying to achieve the fat model/skinny controller goal, what am I missing here. How can I achieve a paginated result while still having the model (properly) do the work of managing and finding the data?

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: