2012-08-17 66 views
0

我正在为应用程序使用yii框架,我需要一组用户使用远程服务器进行验证。在Yii框架中使用远程服务器验证用户

我在我的应用程序中有几个用户角色。为前:

  • 超级管理员
  • 品牌管理
  • 客户 等...

所有客户记录都在一个远程MySQL数据库。我必须通过我的yii应用程序认证客户。我的yii应用程序将托管在不同的服务器上。

请假设我可以在远程服务器中放置一个php脚本来响应我的发布请求。

我需要写我自己的UserIdentity类来做到这一点吗?

请帮我解决这个问题。 谢谢

回答

2

我不认为你需要把任何脚本在您的远程服务器上,你需要的是

1. Access the remote Db, and Yii allows the use of [multiple-databases][1]. 
2. Adjust the model(s) you are using for Authentication/Authorization (usually the User model) to load it's data from the remote database 

对于第一个任务:

// protected/main/config.php 

return array(
... 
'components' => array(
    'db' => array(
     'connectionString' => 'mysql:host=dbserver1;dbname=my1db', 
     ... 
    ), 
    'remotedb' => array(
     'connectionString' => 'mysql:host=adserver2;dbname=advertisingDB', 
     'username'   => 'username', 
     'password'   => '***********', 
     ... 
     'class'   => 'CDbConnection'   // DO NOT FORGET THIS! 
    ), 

对于第二个任务:

对于您使用的型号身份验证 & 授权,您将需要覆盖getDbConnection()函数从远程服务器加载所需的数据。 检查Wiki如何

而且,是的。您需要编写自己的UserIdentity类,实际上它是一项常用任务,即使您不使用远程Db也是如此,因为它的默认逻辑仅仅是一个示例,并非真正的生产站点。

GoodLuck!

+0

嗨,Nimir,谢谢你的帮助。作为您的建议,我创建了另一个远程用户身份验证用户模型。现在一切都很好! – Shakeel 2012-08-21 08:58:40

+0

很高兴工作:) – Nimir 2012-08-21 19:43:16

0

是的,你将不得不重写组件UserIdentity并创建自己的规则认证。

相关问题