Cro*_*O'M 1 php controller cakephp
我有CakePHP控制器代码,它抛出以下错误'致命错误:在非对象上调用成员函数create()'.
控制器代码如下:
if ($this->request->is('post')) {
$this->MonthlyReturn->create();
$this->MonthlyReturn->saveField('company_id', $cid); // Assign current company ID to this monthly return before saving
if ($this->MonthlyReturn->save($this->request->data)) {
$this->Session->setFlash(__('The monthly return has been saved'));
$this->redirect(array('action' => 'index'));
} else
{
$this->Session->setFlash(__('The monthly return could not be saved. Please, try again.'));
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
ori*_*ori 10
如果$uses在控制器内部定义,则需要显式加载MonthlyReturn模型:
var $uses = array('MonthlyReturn','Employee','Company');
Run Code Online (Sandbox Code Playgroud)
见文档