I'm new to cakephp, but from what I understand all of the database interaction should take place in the model.
I followed the official cakephp blog tutorial but they use the controller to save, edit, and delete posts instead of the model. http://book.cakephp.org/2.0/en/tutorials-and-examples/blog/part-two.html
I'm attempting to split up the program so the model takes care of all of the DB interactions. I was able to get it to save new entries, however I can't seem to figure out how to edit them.
Here's the original action used by the official cakephp tutorial for editing posts.
public function edit($id = null) {
$this->Post->id = $id;
if ($this->request->is('get')) {
$this->request->data = $this->Post->read();
} else {
if ($this->Post->save($this->request->data)) {
$this->Session->setFlash('Your post has been updated.');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Unable to update your post.');
}
}
}
So, here's my controller action. My controller name is ConcatenatesController and my model is Concatenate. I originally used this to test out concatenating strings.
public function edit($id = null) {
$this->Concatenate->id = $id;
$this->Concatenate->editPost($id);
}
...and the model that goes with it
function editPost($id){
if ($this->save($this->request->data)) {
$this->Session->setFlash('Your post has been updated.');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Unable to update your post.');
}
}
I'm getting the following errors
Notice (8): Trying to get property of non-object [APP/Model/Concatenate.php, line 20]
Fatal error: Call to a member function setFlash() on a non-object in /Applications/XAMPP/xamppfiles/htdocs/cake/app/Model/Concatenate.php on line 24
Line 20 refers to
if ($this->save($this->request->data)) {
and Line 24 is
$this->Session->setFlash('Unable to update your post.');
$this->Post->save($this->request->data)it's instructing the model to do it. - sevenseacat