2011-07-08 39 views
0

我似乎無法在AppController中使用組件?CakePHP,在AppController中使用組件Cookie

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 

請幫幫忙,我不知道我應該做些什麼的想法!

+0

你叫'AppController中:: _ initUser'從view‽ – deceze

+0

不:(我的意思是我,直到我加入'_initUser'呼叫從beforeFilter本身。 會做一些測試與它現在並嘗試總結在問題出在哪裏。 – Angad

回答

0

啊哈!我終於修好了。問題在於我的Facebook組件意外地讀取了class FacebookHelper

我解決了這個問題,然後它繼續正常執行AppController的其餘部分,它工作。

永遠不會再次在午夜後編碼。

相關問題