在非对象cakephp上调用成员函数create()

时间:2015-05-18 03:16:50

标签: cakephp

public function add() {
        if ($this->request->is('post')) {

                     $site_id = $this->Site->id;
            $this->Site->create();

             $this->request->data['Site']['created_id']  = $this->Auth->user('id');

            if ($this->Site->save($this->request->data)) {

                            $this->request->data['Siteequipment']['site_id']=$this->Site->id;
                            $this->request->data['Siteequipment']['sitecodes']=$this->request->data['Site']['sitecodes'];
***`**strong text**`***                        
                             foreach ($this->request->data['Item'] as $key => $data) {
                              if($key !== 'xx' ) {

                              $data['created_id'] = $this->Auth->user('id'); 
                              $data['modified_id']= $this->Auth->user('id');

                                $this->Site->Siteequipment->create();
                                $this->Site->Siteequipment->save($data);
                                $this->Site->Siteequipment->save($this->request->data);
                     }

                              } 

我有问题一直提到在非对象上创建

1 个答案:

答案 0 :(得分:0)

也许是因为你没有在该案例中加载模型使用它。

$this->loadModel('Site');