Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to bind model at runtime in cakephp

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 629
    Comment on it

    Hello guys,
    Most of time we need to bind model at runtime, So cakephp provides inbuilt function bindModel(). Using this function we can associates model according to requirement .

    Using this technique we dont need to association in Model. It will bind model at the runtime and fetch data with association and also use recursive as per the requirement.

    For Example:-

    $this->Member->bindModel(
                   array(
                     'hasMany'=>array(
                         'NpoMember' =>array(
                          'className' => 'NpoMember',
                          'foreignKey' => 'member_id',
                          'conditions' => array('NpoMember.status' => 'Active'),
                      ) 
    ) ) ); $this->NpoMember->bindModel( array( 'belongsTo'=>array( 'Npo'=>array( 'className' => 'Npo', 'foreignKey' => 'npo_id', 'conditions' => array('Npo.status' => 'Active') )
    ) ) ); $userData = $this->Member->find('first',array('conditions'=>array('Member.email'=>$userEmail,'Member.password'=>$passWord,'Member.status'=>'Active')));

 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: