Silverstripe PHP 脸书
我想在我的 PHP SilverStripe 网站中实现 Facebook 逻辑。 如果用户已登录,我想显示一些文本,否则我想显示 FB 登录按钮。我该怎么做?
我尝试了一些东西:
<?php
class Page extends SiteTree
{
public static $db = array();
public static $has_one = array();
}
class Page_Controller extends ContentController
{
public static $allowed_actions = array();
public function init()
{
require 'facebook/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'xxxxx',
'secret' => 'xxxxx',
'cookie' => true, // enable optional cookie support
));
$session = $facebook->getSession();
}
}
谢谢!
I would like to implement a Facebook logic into my PHP SilverStripe site.
If a user is logged-in I would like to show some text otherwise I would like to show the FB login button. How should I do this?
I tried something:
<?php
class Page extends SiteTree
{
public static $db = array();
public static $has_one = array();
}
class Page_Controller extends ContentController
{
public static $allowed_actions = array();
public function init()
{
require 'facebook/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'xxxxx',
'secret' => 'xxxxx',
'cookie' => true, // enable optional cookie support
));
$session = $facebook->getSession();
}
}
Thx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Silverstripe 已经有一个 facebook-connect 模块,可以提供所有此类功能。它提供与 Silverstripe 登录集成的 facebook 登录。
您可以在此处找到它。
There is already a facebook-connect module for Silverstripe that provides all of this sort of functionality. It provides facebook login that is integrated with the Silverstripe login.
You can find it here.
只需在控制器中添加一个返回 true/false 的 LoginStatus() 方法即可。
然后在您的 Page.ss 模板中您可以只使用一个简单的条件语句:
Just add a LoginStatus() method in the controller that returns true/false.
Then in your Page.ss template you can just use a simple conditional statement: