3

私は関数を持っています。会社プロファイルにはHABTMとユーザーコントローラーの関係があり、共同テーブルcompanys_usersがあります。私の関数は

ublic function company_profile(){
//$logo= $this->Upload->upload('/img/company_logo', $this->data['logo']['a'],null, array('image/jpeg', 'image/jpg', 'image/png'));
$log = $this->Auth->User('id');
    // retrieve the data of the currently logged in user
$user = $this->User->find('first',array(
            'conditions'=>array('User.id'=>$log),
            'recursive'=>1
));
    //pr($user);exit();
    if($this->request->is('post') || $this->request->is('put')){
        //pr($this->request->data);exit;
        //pr($this->data);exit();
        if(isset($user['Company']) && !empty($user['Company'])){
        $newcompany = array();
        $this->User->Company->id = $user['Company'][0]['id'];
        $newcompany['Company'] = $this->data['Company'][0];
        $newcompany['Company']['id'] = $user['Company'][0]['id'];
        //pr($newcompany);exit();
        $this->User->Company->save($newcompany);
        }else{
        $this->User->Company->create();
        $newcompany = array();
        $newcompany['Company'] = $this->data['Company'][0];
        $newcompany['Company']['user_id'] = $log;
        pr($newcompany);exit();

        //newlogo = $this->request->data;
        //$newlogo['Company']['logo'] = $logo['urls']['0'];
        $this->User->Company->save($newcompany);
        //pr($newcompany);exit();
        $this->Session->setFlash('Company Profile Saved Successfully.');
        $this->redirect('/users/dashboard');

        }



    }else{
    $this->request->data = $this->User->read(null, $log);
    }
$this->loadModel('Category');
$categories = $this->Category->find('list');
$this->set(compact('user','categories'));

}

ジョイントテーブルに保存されないのはなぜですか? 現在、この配列を持っているジョイントテーブルに保存する方法を教えてください

Array ( [Company] => Array ( [id] => [category_id] => 1 [name] => Infoperks Solutions [説明] => Web 開発 [user_id] => 1 )

)

4

1 に答える 1