this main.php file:
'db' => array( 'connectionstring' => 'mysql:host=myhost;dbname=mydb', 'emulateprepare' => true, 'username' => 'myuser', 'password' => 'mypass', 'charset' => 'utf8', ), 'dbanother' => array( 'connectionstring' => 'mysql:host=myhost;dbname=mydb2', 'emulateprepare' => true, 'username' => 'myuser2', 'password' => 'mypass2', 'charset' => 'utf8', 'class' => 'cdbconnection' ),
in useridentity components have this:
public function authenticate() { ......... $loggedinuser = user::model()->find("username = :username", array("username" => $this->username)); ...... }
and in user model , want use table users mydb2 database:
class user extends cactiverecord { private $connection_db2; /** * @see db connections config/main.php */ public function __construct(){ $this->connection_db2= yii::app()->dbanother; } public static function model($classname=__class__){ return parent::model($classname); } public function tablename() { return yii::app()->dbanother->users; // here want declare want use table **users** } ..... }
at moment getting this:
property "cdbconnection.users" not defined.
can me ? thx
it's simpler :) override getdbconnection()
method in class:
public function getdbconnection() { return yii::app()->dbanother; }
Comments
Post a Comment