TL; DR:
OK to invoke find() from your controller, however it is best to put all / all find () s in your models .
If you are used to placing all your find() in your models, this will greatly simplify your code in the long run.
Explanation / for example:
In this case, for example, you can start with a seemingly simple function:
//User model public function getUsers() { return $this->find('list'); }
But later, maybe you will need something more line by line:
//User model public function getUsers($opts = array()) { $defaults = array( 'findType' => 'all', 'activeOnly' => true, ); $params = array_merge($defaults, $opts); $qOpts = array('conditions' => array()); //active only if(!empty($params['activeOnly'])) $conditions[$this->alias.'.active'] = 1; return $this->find($params['findType'], $qOpts); }
(Sorry, if there are many ways to make this code better - it was just in my head - this gives you an idea.)
Saving all your find() in the Model also prevents you from searching for each controller every time you want to write find() to determine if you are using a similar find() somewhere else. If you program as a team, this can be a nightmare, and you will almost certainly duplicate the code.
source share