Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Advantage of "loadModel" over "$uses"

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 269
    Comment on it

    Advantage of loadModel over uses

    While using "$uses", many unrelated model gets loaded. So it's best practice to use it only when it is needed through out the controller. If you only need it randomly then loadModel(). Another way of loading a model, if it is in a relationship $this->User->Photo->whatever().
    It's syntax is stated below:-

    Code
    
    $this->load(ModelName);
    $this->ModelName->whatsoever();
    
    OR
    
    Another option is to use this approach:
    $ModelName = ClassRegistry::init(ModelName);
    
    Which is nice, because it allows you to do things like this:
    
    $someData = ClassRegistry::init(MyModel)->find(all, array(conditions => array(MyModel.name LIKE => % . $name . % ))); (the latter, chaining, example is PHP5 only).
    

 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: