yii - Using Multiple Database Connection Not Working For Extension -


I'm making many database connections using the tutorial. The code is working fine in the model but the problem is that I am using an extension where I have the Yi :: app () - gt; & Gt; Db; Here I am getting the exception property "CWebApplication.dbadvert" is not defined. The extension of the extension has been enhanced by the CExtController. Please help.

In the example you are setting dbadvert for custom code records class RActiveRecord , not for web application.

If you would like it to be Yii :: app () -> gt; Dbadvert , you will need to set it up in your config.php section

  'dbadvert' = & gt; Array ('class' = & gt; 'CDbConnection' * parameter * *),   

UPD

A wrapper component for you You can create CDbConnection, which you want in any way to change the connection string and put it as a webapp component.

  & lt ;? Php class CMultiuserDatabaseConnection CaptureComment {public function __call ($ name, $ params) {$ db = $ this- & gt; Db; Return call_user_func_array (($ db, $ name), $ params); } Public $ dbConnectionClass = 'CDbConnection'; Public $ connection = zero; Public $ default configuration = null; Public function getDatabaseConfiguration ($ user) {if (! $ This-> Connection) {Return Array (); } Return_key_exists ($ user, $ this-> connection)? $ This- & gt; Connection [$ user]: $ this- & gt; Default configuration; } Public function getDb () {$ user = Yii :: app () - & gt; the user; If ($ user- & gt; isGuest) {return false; } $ Username = $ user- & gt; Name; $ Config = $ this- & gt; getDatabaseConfiguration ($ username); If (! $ Config) {return false; } $ Dsn = array_key_exists ('dsn', $ config)? $ Config ['dsn']: Faucet; If (! $ DSN) {return false; } $ User = array_key_exists ('user', $ config)? $ Config ['user']: faucet; $ Password = array_key_exists ('password', $ config)? $ Config ['password']: zero; $ Result = new $ this- & gt; DbConnectionClass ($ dsn, $ user, $ password); Return result; }}   

This is a raw example of the component, which you can set as your 'DB' component, and then you can set the 'Connection' to store the per-user configuration The way to get the option:

  'component' = & gt; Array (... 'db' = & gt; array ('class' = & gt; "CMultiuserDatabaseConnection", 'connection' = & gt; array ("first user name" => array = (// just other db Configuration here, for user-one), "second-user-name" = & gt; array (// just for other DB configuration herer, for two users), ...), 'default configuration' = & gt; The array (/ * * goes to the configuration for all other users, which were not specified in the connection. * /),), ...),    

Comments

Popular posts from this blog

python - Writing Greek in matplotlib labels, titles -

c# - LINQ to Entities does not recognize the method 'Int32 IndexOf(System.String, System.StringComparison)' method -

Pygame memory leak with transform.flip -