本文介绍了CakePHP:调用非对象上的成员函数setFlash()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试注销我的CakePHP应用程序时,得到以下错误:

I get the following error when trying to logout of my CakePHP app:

Notice (8): Undefined property: UsersController::$Session [APP/controllers/users_controller.php, line 75]
Fatal error: Call to a member function setFlash() on a non-object in /Users/cameron/Sites/cakeapp/app/controllers/users_controller.php on line 75

这是第74,75和76行的代码:

This is the code for lines 74, 75 and 76:

function logout() {
    $this->Session->setFlash('Good-Bye');
    $this->redirect($this->Auth->logout());
}


推荐答案

默认情况下,会话组件应该被加载,但是如果你在AppController中设置了components数组,这将会覆盖默认值。

The Session component should be loaded by default, but if you've set the components array in AppController this will overwrite the defaults.

这意味着如果你有

var $components = array();

,请确保会话组件包含在其中:

in your AppController, make sure the Session component is included there:

var $components = array('Session');

或者,如果您不想使用它,您可以在用户控制器中加载Session组件应用程式。

Alternatively, you can load the Session component in your Users controller if you don't want to use it app-wide.

这篇关于CakePHP:调用非对象上的成员函数setFlash()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 13:27