Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Fat models with skinny controllers in cakephp

    • 0
    • 3
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 310
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: