Yii 1.1 or above
To set up the widget, download and extract under protected/components folder.
To render the widget for all view, you need to add the following code snippet to your main layout, place it between breadcrumbs and content:
............ <?php if(isset($this->breadcrumbs)): <?php $this->widget('zii.widgets.CBreadcrumbs', array( 'links'=>$this->breadcrumbs, )); <!-- breadcrumbs --> <?php endif // this is the widget <?php $this->widget('Flashes'); <?php echo $content; ............
Example usage in controller: Just like using original setFlash Yii function. Types of messages that can be used is 'success', 'error', and 'notice'.
........ public function actionUpdate($id) { $model=$this->loadModel($id); if(isset($_POST['Post'])) { $model->attributes=$_POST['Post']; if($model->save()){ // here is the code to set flash message Yii::app()->user->setFlash('success','Save data successfully'); $this->redirect(array('view', 'id'=>$model->id)); } } $this->render('update',array( 'model'=>$model, )); } ...........
Total 1 comment
Not a huge gain but as a page load performance gain I would move the if ($flashMessages) check up above the register JS part as theres no point registering the JS if there are no flashes. I aslo made style configurable if desired (although possibly overkill) i.e.
Leave a comment
Please login to leave your comment.