CakePHP会话组件错误

时间:2012-07-24 12:41:28

标签: php cakephp cakephp-2.0 fatal-error

在我的CakePHP应用程序中,当我使用另一个控制器的类时,我得到会话读取功能错误。

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错误。

2 个答案:

答案 0 :(得分:4)

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

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

答案 1 :(得分:0)

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