【问题标题】:CakePHP Session component errorCakePHP Session 组件错误
【发布时间】:2012-07-22 18:51:34
【问题描述】:

在我的 CakePHP 应用程序中,当我使用另一个控制器的类时,我收到 Session read function 错误。

example.com/app/getList 运行良好
example.com/seconds/parseList 运行良好
但是example.com/first/index 给出了这个错误:

Fatal error: Call to a member function read() on a non-object in
/example.com/app/Controller/AppController.php on line 468

第 468 行是这样的:$list=$this->Session->read('myList');

我该如何解决这个问题?

class FirstController extends AppController {
    public function index () {
        $Seconds = new SecondsController();
        $Seconds->parseList();
    }
}

class SecondsController extends AppController {
    public $helpers = array('Html', 'Session');

    public function parseList () {
        $output = $this->getList();
        return output;
    }
}

class AppController extends Controller {
    public $uses = array('App', 'Mydata');
    var $components    = array('Session');
    public $helpers = array('Session','Html','Cache');

    public function getList () {
        $list=$this->Session->read('myList');
        return $list;
    }
}

编辑:我应该提到example.com/app/getList 运作良好。当我独立运行此操作时,它不会给出 Session 错误。

【问题讨论】:

  • 在 /app/config/core.php 中是否将 AUTO_SESSION 设置为 false。??

标签: php cakephp cakephp-2.0 fatal-error


【解决方案1】:

您必须在手动创建控制器实例后调用constructClasses() 方法:

$Seconds = new SecondsController();
$Seconds->constructClasses();

【讨论】:

  • 我的错。我错过了constructClasses。这对我帮助很大。非常感谢。
  • 当我们从任何其他地方(如 Helper)调用控制器时会导致此错误。谢谢@dhofstet
【解决方案2】:

您是否将 var $components = array('Session'); 放入您的 AppController 中?

【讨论】:

    猜你喜欢
    • 2013-10-29
    • 1970-01-01
    • 1970-01-01
    • 2012-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 1970-01-01
    相关资源
    最近更新 更多