I can’t seem to use a component in 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.
.
.
.
Here is the error PHP is throwing up:
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
Please help, I have no idea about what I should do!
Aha! I fixed it finally. The problem was that my Facebook component read
class FacebookHelperaccidentally.I fixed this issue and then it continued to execute the rest of AppController normally and it worked.
Never going to code post-midnight again.