CakePHP 致命错误:在非对象(控制器)上调用成员函数 create()
我有 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.'));
}
}
任何帮助将不胜感激。
I have CakePHP Controller code which is throwing up the following error 'Fatal error: Call to a member function create() on a non-object'.
The controller code is as follows:
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.'));
}
}
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在控制器中定义
$uses
,则需要显式加载MonthlyReturn
模型:请参阅 文档
If you define
$uses
inside your controller you need to explicitly load theMonthlyReturn
model:See documentation
你应该首先像这样加载模型
$this->loadModel("MonthlyReturn");
这里的 MonthlyReturn 是模型的名称。
you should load the model first like this
$this->loadModel("MonthlyReturn");
Here the MonthlyReturn is the name of the Model.