Hello Readers,
We have a session helper in cakephp which is known as setFlash() basically use for showing messages after login successfully , user registration etc.
First of all we have to assign the session helper in Controller.
Code use in Controller:
public $Helpers = array('Session','Html');
public function contact us(){
if($this->request->data){
if($this->Contact->save($this->request->data)){
$this->Session->setFlash("*Thanks For Contacting Us! We will get you Soon.");
$this->redirect(array('controller'=>'users','action'=>'contact us'));
}
else{
$this->Session->setFlash("Data Not Saved",'default');
$this->redirect(array('controller'=>'users','action'=>'contact us'));
}
}
}
above code explains that when contact details successfully saved in database then show the Thank you message otherwise show the error message.
Code use in Contact us ctp
<html>
<?php echo $this->Session->flash();?>
//
write html code here
//
</html>
In above code <?php echo $this->Session->flash();?> simply echo your message which you provided in controller.
0 Comment(s)