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
請幫幫忙,我不知道我應該做些什麼的想法!
你叫'AppController中:: _ initUser'從view‽ – deceze
不:(我的意思是我,直到我加入'_initUser'呼叫從beforeFilter本身。 會做一些測試與它現在並嘗試總結在問題出在哪裏。 – Angad