CakePHP,在AppController中使用组件Cookie

时间:2011-07-08 18:55:18

标签: cakephp cakephp-1.3

我似乎无法在AppController中使用组件?

class AppController extends Controller {
    var $helpers = array('Facebook', 'Session', 'Menu', 'Html', 'Form'); // Facebook is a custom helper.
    var $components = array('Cookie');

    function beforeFilter ( )
    {
        $this->Cookie->name = '[removed]';
        $this->Cookie->path = '/cake/';
        $this->Cookie->domain = 'localhost';
        $this->Cookie->key = '[removed]';

        $this->_initUser();
    }

    function _initUser ( )       // Using this for a cleaner default.ctp
    {
        @Controller::loadModel('User');

        // DEFINE facebook variables globally
        $GLOBALS['APP_ID'] = '[removed]';
        $GLOBALS['APP_SECRET'] = '[removed]';
        $GLOBALS['REDIRECT_URI'] = 'http://localhost/cake';

        // Check if logged in with Facebook.
        if($this->Cookie->read('User') == null && isset($_GET['code']))    // Line 57.  
.
.
.

这是PHP抛出的错误:

Notice (8): Undefined property: View::$Cookie [APP\app_controller.php, line 57]Code
        // Check if logged in with Facebook.
        if($this->Cookie->read('User') == null && isset($_GET['code']))  AppController::_initUser() - APP\app_controller.php, line 57
include - APP\views\layouts\default.ctp, line 47
View::_render() - CORE\cake\libs\view\view.php, line 731
View::renderLayout() - CORE\cake\libs\view\view.php, line 489
View::render() - CORE\cake\libs\view\view.php, line 435
Controller::render() - APP\controller.php, line 909
PagesController::display() - APP\controllers\pages_controller.php, line 83
Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 204
Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 171
[main] - APP\webroot\index.php, line 83

Fatal error: Call to a member function read() on a non-object in C:\xampp\htdocs\cake\app\app_controller.php on line 57

请帮忙,我不知道该怎么做!

1 个答案:

答案 0 :(得分:0)

啊哈!我终于修好了。问题是我的Facebook组件意外地读了class FacebookHelper

我解决了这个问题,然后继续正常执行AppController的其余部分并且工作正常。

永远不会再在午夜后编码。