【问题标题】:$this->Session->setFlash() display an error in cakephp 2.3.7$this->Session->setFlash() 在 cakephp 2.3.7 中显示错误
【发布时间】:2013-07-17 07:43:50
【问题描述】:

我是 cakephp 新手,我正在尝试在我的代码中使用 $this->Session->setFlash() 并且它说有一个错误:调用非成员函数 setFlash()目的!这是我的代码

function add(){
    if(!empty($this->data)){
        if($this->Post->save($this->data)){               
            $this->Session->setFlash('The post was successfully added');
            $this->redirect(array('action'=>'index'));
        }else{
            $this->Session->setFlash('The post was not saved, please try again');
        }
    }
}

我能做些什么来解决这个问题?

【问题讨论】:

    标签: php cakephp frameworks cakephp-2.3


    【解决方案1】:

    检查 app/Controller/AppController.php 你在$components 字段中有'Session' 元素。

      var $components =  array('Session');
    

    【讨论】:

      【解决方案2】:

      首先你必须在你的控制器代码中添加这个:

           var $components= array('Session');
      

      它肯定会起作用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-07-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-03-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多