In fat model and skinny controllers method we write our database query in model. Normally we use validation rules and model binding in our model and all query write in controllers but as we know that when url routing requests first comes to controller, our controller should have less code to make application fast.
For example, normally we use like this
class BlogsController extends AppController {
public function bloglist(){
$user_id = $this->Auth->user('id');
if(user_id)
$blogs = $this->Blog->find('all', array('conditions' => array('Blog.author_id' => $user_id)));
else
$blogs = $this->Blog->find('all');
}
}
but in fat model and skinny controllers we use find method in our model
class Blog extends AppModel {
public function get_post($user_id='') {
if($user_id)
$blogs = $this->find('all', array('conditions' => array('Blog.author_id' => $user_id)));
else
$blogs = $this->find('all');
return $blogs;
}
}
class BlogsController extends AppController {
public function bloglist(){
$user_id = $this->Auth->user('id');
$blogs = $this->Blog->get_post($user_id)));
}
}
0 Comment(s)