【发布时间】:2015-03-30 20:33:31
【问题描述】:
问题: 在我的控制器功能中出现以下错误。初始保存正在工作,看起来它被嵌套保存功能阻塞了。关于我为什么会收到此错误的想法?
错误:
致命错误
错误:在非对象上调用成员函数 read()
文件:C:\metroapps\Orders\app\Controller\OrderLogsController.php
线路:121
注意:如果要自定义此错误信息,请创建 app\View\Errors\fatal_error.ctp
代码:
public function quickAdd($notes = null,$order_id =null, $log_type_id = null) {
$this->request->data['OrderLog']['log_type_id'] = $log_type_id;
$this->request->data['OrderLog']['order_id'] = $order_id;
$this->request->data['OrderLog']['notes'] = $notes;
$this->OrderLog->create();
if ($this->OrderLog->save($this->request->data)) {
$this->Session->setFlash(__('The order log has been saved.'));
$this->Order->read(null, $order_id);
//set checkedout to false
$this->Order->set('checked_out', 0);
$this->Order->set('checked_out_by', null);
$this->Order->save();
return $this->redirect(array('controller' => 'orders','action' => 'view',$order_id));
} else {
$this->Session->setFlash(__('The order log could not be saved. Please, try again.'));
}
$orders = $this->OrderLog->Order->find('list');
$logTypes = $this->OrderLog->LogType->find('list');
$this->set(compact('orders', 'logTypes'));
}
【问题讨论】:
-
可能有两个问题。如果您在模型对象上调用函数,那么您必须在调用它的函数中加载它。如果您正在调用控制器函数,请先尝试为其创建对象,然后使用它来调用该函数