【发布时间】:2014-06-05 14:23:37
【问题描述】:
我有两个站点,一个是父站点 www.example.com(在 drupal 中开发),另一个站点是子域,比如说 app.example.com (在 Yii 中) 现在用户使用 drupal 站点登录,一旦登录,它可以访问 app.example.com ,我需要 yii 中的用户详细信息。
目前, Yii::app()->user->isDrupalAuthenticated() 即使用户登录也总是返回 false。
*在创建子域之前,我使用 www.example.com/app 访问 yii 站点,它工作正常。但是现在它的创建问题
我在 yii 中有这段代码:-
class LoginController extends Controller {
public $defaultAction = 'initialize';
public function actionInitialize() {
$this->verifyDrupalUserIdentity();
}
private function verifyDrupalUserIdentity() {
new DrupalUserIdentity();
if (!Yii::app()->user->isDrupalAuthenticated()) {// check if user logged in
header('refresh:5;url=http://www.example.com');
Yii::app()->end();
exit;
}
}
}
define('DRUPAL_ROOT', '/var/www/example');
define('BASE_URL', 'http://www.example.com/');
class DrupalUserIdentity extends CUserIdentity {
/**
* Overriding the default constructor inherited from CUserIdentity
*/
public function __construct() {
$this->authenticate();
}
public function authenticate() {
global $base_url;
$base_url = BASE_URL';
$currentPath = getcwd();
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
require_once DRUPAL_ROOT . '/includes/errors.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
chdir($currentPath);
global $user;
$this->username = $user->name;
$this->_id = $user->uid;
new DrupalUser();
Yii::app()->user->setDrupalAttributes($user);
}
}
class DrupalUser extends CWebUser {
private $_attributes;
public function setDrupalAttributes($attributes) {
$this->_attributes = $attributes;
}
public function getDrupalAttribute($att) {
if ($this->_attributes->$att) {
return $this->_attributes->$att;
}
}
public function isDrupalAuthenticated() {
if ($this->_attributes->uid > 0) {
return true;
}else
return false;
}
public function getId() {
return $this->_attributes->uid;
}
}
【问题讨论】:
标签: php session drupal yii drupal-7