Issue: Getting the following error in my controller function. The initial save is working, it looks like it's getting choked up on the nested save function. Thoughts as to why i would be getting this error?
Error: Fatal Error Error: Call to a member function read() on a non-object File: C:\\metroapps\\Orders\\app\\Controller\\OrderLogsController.php
Line: 121
Notice: If you want to customize this error message, create app\\View\\Errors\\fatal_error.ctp
Code :
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'));
}
You probably need to fix your model relations and access the related model properly.
Make sure your Order and OrderLog models are related (both directions)
// in Order model public $hasMany = array('OrderLog'); // in OrderLog model public $belongsTo = array('Order');
and then in your function do
$this->OrderLog->Order-> .. // instead of $this->Order
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.