Nutty Nur
Nutty Nur

Reputation: 91

Cakephp: $session->flash(); gives error to me

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'));
        }
    }
}

Upvotes: 1

Views: 556

Answers (2)

dhofstet
dhofstet

Reputation: 9964

You have to use $this->Session->flash() in your layout, $session->flash() is the approach used in CakePHP 1.x.

Upvotes: 2

Deepu Thomas
Deepu Thomas

Reputation: 43

$this->Session->setFlash(__('Post deleted', true)); why using double under score you can simply use

$this->Session->setFlash('Post deleted');

Upvotes: -1

Related Questions