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.
If you define
$usesinside your controller you need to explicitly load theMonthlyReturnmodel:See documentation