0

Possible Duplicate:
Call to a member function on a non-object

I'm doing this tutorial here: http://tv.cakephp.org/video/webtechnick/2011/01/12/nick_baker_--_facebook_integration_with_cakephp

I baked a new project with cake bake facebook_app and set the configuration database file to the correct settings and the default cakePHP screen showed that tmp directory was writable, DB setup was good, etc.

I downloaded the CakePHP plugin by WebTechNick here: https://github.com/webtechnick/CakePHP-Facebook-Plugin, and filled out app information (app_secret, app_id, etc), adding it to facebook_app/config/facebook.php

Changed facebook_app/app_controller.php:

class AppController extends Controller {
var $name = 'Facebook';
var $helpers = array('Session', 'Facebook.Facebook');
}

Then just exactly as in the tutorial `facebook_app/views/pages/home.ctp':

<h1>Facebook_App</h1>
<?php $this->Facebook->share(); ?>

returning the error message: Undefined property: View::$Facebook

I realize that means PHP didn't recognize Facebook as an object. But I installed the plugin!

Also, it seems not MVCish to have something like $this->Facebook->share(); in a view (home.ctp). However, this is exactly how WebTechNick does it in his tutorial (I followed it exactly 3x) and it does not work for me. I'm a complete noob at cakePHP (although I've read the entire documentation) and I'm just trying to learn and understand through examples. enter image description here

Community
  • 1
  • 1
lollercoaster
  • 15,969
  • 35
  • 115
  • 173

2 Answers2

1

I was having this problem and I found that the plugin I was using was for CakePHP 1.3 and I was using Cake 2.0. I found the BETA branch for the upgraded Cake 2.0 and it worked perfect.

Here is the Cake 2.0 BETA Branch

sbonkosky
  • 2,537
  • 1
  • 22
  • 31
1

:) To be fair, it's PHP - you didn't install anything. Or if you prefer, "install" != "invoke." PHP is really amazingly easy to debug. I mean, it tells you exactly what's wrong:

Like turning to a channel that's not on the air, the error your getting means that the object you're calling doesn't actually exist, at least not in the scope you're trying to invoke it.

Is that your IDE? Is it set up for your Cake app? Are you sure the instructions were to set your AppController's $name to 'Facebook' instead of $name = Facebook_App in your AppController? It looks like you either replaced your actual app's AppController with the plugin files instead of putting them in the proper directory, or the plugin is not deferring / calling / extending / returning to the application the way it's supposed to. Knee jerk -> typo, naming conflict, path problem, permissions.

Cake's not even rendering. I can tell because your screenshot would show that error with the styled Cake errors. That tells you it's erroring before AppController class makes it to View class.

Create an instance of the Facebook object statically in the view and see what happens. Then, what does

function beforeFilter() {
    parent::__construct() ?
}

get you? Anything? What about debug(), var_dump, the object functions will also shed light on what's happening. So will your logfiles.

Btw, if you don't use them already: Firefox + FirePHP + Xdebug = made of win.

OpenSorceress
  • 2,014
  • 16
  • 21