如何在yii框架中显示消息?

时间:2014-04-22 07:58:03

标签: php yii

我正在做一份工地工作。我有一个控制器Sitecontroller。我无法使用setFlash功能显示消息。视图页面中的IE setFlash('success', "Job saved!"),视图页面是`search_detail.php'。

我的控制器是Sitecontroler.php

<?php
public function actionsearch_detail()
  {
    $job_id=$_GET['job_id'];
    $status=$_GET['status'];
    $model = new Job ;
    $model=Job::model()->find(array('select'=>'*',"condition"=>"id=$job_id",));
    if($status==1)
    {
      $session_id=Yii::app()->session['user_id']; 
      if($session_id == "")
       {
        $this->redirect( array('/employee/site/login'));
       }
      $user_id  =$session_id;   
      $model2 = new save_job;
      $model2->user_id=$user_id;
      $model2->job_id=$job_id;
      if($model2->save())
       { 
        Yii::app()->user->setFlash('success', "Job saved!"); 
       }
    }
 $this->render('search_detail',array('model' =>$model,'job_id' =>$job_id,'status'=>0));
  }
 ?>

1 个答案:

答案 0 :(得分:1)

您需要在视图中显示

<?php
    foreach(Yii::app()->user->getFlashes() as $key => $message) {
        echo '<div class="flash-' . $key . '">' . $message . "</div>\n";
    }
?>

Link