0

I have to edit a form where it contains datas form two tables. one is master and another user. first the data is saved in user table and with that id the remaining datas get saved in master table. Below is my edit code.What should i do to fetch the data and edit it.

     public function edit() {
    $id = $this->request->params['pass'][0];
    $this->Master->id = $id;
    if( $this->Master->exists()){
        if( $this->request->is( 'post' ) || $this->request->is( 'put' ) ){
            if( $this->Master->save( $this->request->data ) ){
                $this->redirect(array('action' => 'index'));
            }
            else { 
                $this->Session->setFlash('Unable to edit row. Please, try again');
            } 
        }
        else { 
          $this->request->data = $this->Master->read();
        }
    } 
}

Could somebody help pls..

3
  • why you fetching the data. With user table id you can edit user fields. match user id and user_id in master table. if same then get master table id and edit master fields. This is what i understood. if i am wrong pls explain more your question. Commented Jan 12, 2016 at 5:35
  • If you got your answer what you need then i am posting my command in answer. pls confirm me Commented Jan 12, 2016 at 5:38
  • pls explain more and tell me what output you want Commented Jan 12, 2016 at 5:40

1 Answer 1

1

Update your code by :

$this->request->data = $this->Master->read(null, $id);

$this->set('masterArr',$this->Master->find('all',array('conditions' =>
array('Master.id ' => $id))));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.