I am quite new at cakephp despite using it several years ago in the older version of cakephp for school. Now it requires us to use $session->flash(); to display our error messages. I placed it in my view/layouts/default.ctp and this is what i got
Call to a member function flash() on a non-object in
C:\xampp\htdocs\blog\app\View\Layouts\default.ctp on line 9
here are my codes:
class PostsController extends AppController {
var $name = 'Posts';
var $helpers = array('Html', 'Form', 'Session');
public function delete($id = null) {
$this->Post->id = $id;
if (!$id) {
$this->Session->setFlash(_('Post does not exist!', true));
$this->Session->redirect(array('action'=>'index'));
}
if ($this->Post->delete($id)) {
$this->Session->setFlash(__('Post deleted', true));
$this->redirect(array('action' => 'index'));
}
}
}
You have to use
$this->Session->flash()in your layout,$session->flash()is the approach used in CakePHP 1.x.