CakePHP错误将数据从ModelB设置为ModelA

时间:2015-09-02 19:47:33

标签: cakephp cakephp-2.0

我的负载模型:

array (size=14)
  0 => string 'AppModel' (length=8)
  1 => string 'Log' (length=3)
  2 => string 'LogAppModel' (length=11)
  3 => string 'User' (length=4)

我正在尝试使用set http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-set-one-two-null

将模型User中的数据传递给Log
$this->Log->set('test','data');

但蛋糕给我错误

Error: Call to a member function set() on null  
File: /Volumes/Macintosh HD/Users/Javi/Sites/log/app/Model/User.php 
Line: 198

用户模型:

public function afterSave($created, $options = array()){
        //var_dump(App::objects('model'));die();
        $this->Log->set('test','data'); <------ Line 198
        $this->log('log textttttttttt','status');
    }

所以我需要将User模型中的afterSave中的id传递给Log模型中的beforeSave

日志模型:

public function beforeSave($options = array()) {
        $this->data[$this->alias]['user_id'] = AuthComponent::user('id');
        $this->data[$this->alias]['project_id'] = //I NEED THIS!!!!!!!!;
        return parent::beforeSave($options);
    }

为什么我无法将用户模型中的数据传递给Log模型?

提前致谢

0 个答案:

没有答案