I’m trying to make a Twitter component for CakePHP so I can sign in with Twitter and eventually allow my users to post to Twitter as well, this is my component:
<?php
class TwitterHelperComponent extends Object {
var $name = 'TwitterHelper';
var $twitterObj;
function __construct() {
parent::__construct();
require_once(APP.'vendors/twitter/EpiCurl.php');
require_once(APP.'vendors/twitter/EpiOAuth.php');
require_once(APP.'vendors/twitter/EpiTwitter.php');
$this->twitterObj = new EpiTwitter(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
}
function setOAuthToken($oauth_token) {
$this->twitterObj->setToken($oauth_token);
$token = $this->twitterObj->getAccessToken();
$this->twitterObj->setToken($token->oauth_token, $token->oauth_token_secret);
return $twitter;
}
}
?>
And in my bootstrap.php file I placed the following:
define('TWITTER_CONSUMER_KEY', '*******');
define('TWITTER_CONSUMER_SECRET', '********');
In my controller I set the twitterObj to the view:
function home(){
$this->layout = 'home';
$this->set('twitter', $this->TwitterHelper->twitterObj);
}
And in my view I do the following:
<a class='twitter-button' href='<?php echo $twitter->getAuthenticateUrl(); ?>'></a>
But I just get an undefined variable warning in my view for twitterObj. I’m using this Twitter PHP lib:
Also, my whole interface just goes out of whack and it loses all the styles when I try to get the URL.
I would suggest just retrieving the URL in your controller, and passing that through the set. I’m not sure passing an object reference will work as you intend.