messagestack A way to share messages between models, controllers and views

  1. Requirements
  2. Usage
  3. Installation

This is a small, yet very useful component.

Many times, the models will handle all the processing logic and you will need a way to pass messages from the models back to controllers or even directly to your view.

This component does exactly that, once initialized, it will allow you to collect messages from everywhere and display them in any place you need to.

Because when adding a message, these are stored in key=>value pairs, this makes the component very useful when doing ajax validation and you want to return the response in a json format instead of calling CJSON::encode() followed by Yii::app()->end(); The advantage of using this component for this purpose is that, beside calling the above two methods, it will also append the correct headers for the json format.


Tested on Yii 1.1.7


The component is very small, the following methods are available:

#set a message: 
Yii::app()->messageStack->set($messageKey, $messageValue);  
#get a message  

#get all messages  

#set a JSON response with full headers:  
#[this method will append the correct headers, will json_encode the message array and it will echo it, then it will call Yii::app()->end(); ]

#get the messages in a JSON format  

#remove all the stored messages  

#check if we have some messages in the stack  
//do something here 


In your main.php config file in the components area, add :

'messageStack' => array(  
            'class' =>  'CmsMessageStack',  
10 0
Yii Version: 1.1
License: (not set)
Category: Others
Developed by: twisted1919
Created on: May 3, 2011
Last updated: 10 years ago


show all

Related Extensions