CakePHP - Twitter 组件
我正在尝试为 CakePHP 制作一个 Twitter 组件,这样我就可以使用 Twitter 登录并最终允许我的用户也发布到 Twitter,这是我的组件:
<?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;
}
}
?>
在我的 bootstrap.php 文件中,我放置了以下内容:
define('TWITTER_CONSUMER_KEY', '*******');
define('TWITTER_CONSUMER_SECRET', '********');
在我的控制器中我将 twitterObj 设置为视图:
function home(){
$this->layout = 'home';
$this->set('twitter', $this->TwitterHelper->twitterObj);
}
在我的视图中,我执行以下操作:
<a class='twitter-button' href='<?php echo $twitter->getAuthenticateUrl(); ?>'></a>
但我只是在 twitterObj
的视图中收到未定义的变量警告。我正在使用 这个 Twitter PHP 库:
另外,我的整个界面变得不正常,它当我尝试获取 URL 时丢失所有样式。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议只检索控制器中的 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.