English 中文(简体)
意料:使用模块特定数据库进行出入控制
原标题:Yii: using a module specific database for access control

我试图为一组特别用户建立一个单独的数据库,这些用户将通过一个Yi模块进入我的网站,但我似乎无法正确掌握配置。

Here are the relevant files my module heirarchy.

/protected/modules/special
/protected/modules/special/SpecialModule.php
/protected/modules/special/models/SpecialActiveRecord.php
/protected/modules/special/models/Account.php
/protected/modules/special/components/UserIdentity.php

Per instructions here, I ve updated my main.config to include a module specific database definition.

 modules =>array(
     special =>array(
         db =>array(
             connectionString => mysql:dbname=specialdatabase ,
             username => special ,
             password => special ,
        ),
    ),
),

我还更新了我的模块,以支持数据库定义,将<代码>公开添入了特别单元.php,我建立了利用数据库定义的专门积极记录模块。

class SpecialActiveRecord extends CActiveRecord
{
    public function getDbConnection()
    {
        $db = Yii::app()->controller->module->db;
        return Yii::createComponent($db);
    }
}

Where I m having trouble is in the account model. My primary web application also implements an account model and the stack trace shows that the module is accessing all of my module specific files through user identity (/protected/modules/special/components/UserIdentity.php). The account model that is being used for authorization, however, is referenced at the site level (/protected/models/Account.php).

利用模块特定数据库实施模块具体认证的适当方法的任何想法?

最佳回答

Based on a forum post on the Yii site (that I can t seem to locate now), I overcame this issue by adding prefixes to my module models--eg. SAccount.php and SActiveRecord.php.

Additionally, I had to make minor modifications to the getDbConnection routine to activate the database and get everything working in Yii 1.0 (this might not be the case for 1.1). Here I modified the code from the CActiveRecord class.

class SActiveRecord extends CActiveRecord
{
    public function getDbConnection()
    {
        if(self::$db!==null)
            return self::$db;
        else
        {
            $db = Yii::app()->controller->module->db;
            self::$db=Yii::createComponent($db);
            if(self::$db instanceof CDbConnection)
            {
                self::$db->setActive(true);
                return self::$db;
            }
            else
                throw new CDbException(Yii::t( yii , Special Active Record requires a "db" CDbConnection application component. ));
        }
    }
}
问题回答

暂无回答




相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签