Friday, 9 August 2013

CakePHP Error: Call to a member function save() on a non-object

CakePHP Error: Call to a member function save() on a non-object

I am tryin to run the following action:
public function add() {
if (!empty($this->request->data)) {
// We can save the User data:
// it should be in $this->request->data['User']
$user = $this->User->save($this->request->data);
// If the user was saved, Now we add this information to the data
// and save the Profile.
if (!empty($user)) {
// The ID of the newly created user has been set
// as $this->User->id.
$this->request->data['Employee']['user_id'] = $this->User->id;
// Because our User hasOne Profile, we can access
// the Profile model through the User model:
$this->Employee->save($this->request->data);
}
}
When i run this i get the following error:
Error: Call to a member function save() on a non-object
File: /var/www/bloglic-2013/cake/app/Controller/EmployeesController.php
Line: 61
How come?

No comments:

Post a Comment