mauzilla
mauzilla

Reputation: 3592

cakePHP setFlash cannot find element

I am trying to set a success element to my setFlash.

When I do:

 $this->Session->setFlash("Message");

It shows the message perfectly, however, with a red background. After investigating I can change the element to "success" which should show a nice green background, but when I do:

 $this->Session->setFlash("Message","success");

I get:

 Element Not Found: Elements\success.ctp 

I have verified and there is definately a success.ctp file within my app/View/Elements/ folder.

I am using cakePHP 2.1

** EDIT **

It may be a routing error as I also find that sometimes on redirect it will redirect example users/users/login as appose to users/login/

Upvotes: 0

Views: 1761

Answers (3)

Sedrak  Sargsyan
Sedrak Sargsyan

Reputation: 1

delete true in $this->Session->setFlash('Book is Updated!', true);

Upvotes: 0

Rahuul
Rahuul

Reputation: 26

  1. Move the required layout files into app/views/elements (success.ctp)
  2. Rename the $content_for_layout variable to $message

src.

Upvotes: 1

mauzilla
mauzilla

Reputation: 3592

As per the suggestion by @Learner, the correct code which worked (for me in 2.1) is:

 $this->Session->setFlash('Message.','default',array('class'=>'success'));

Upvotes: 0

Related Questions