Page 1 of 1
Dynamic change table name in AR
#1
Posted 18 January 2010 - 08:27 PM
Hi,
is it possible to dynamic set table name in AR before I will create object of model?
is it possible to dynamic set table name in AR before I will create object of model?
#2
Posted 19 January 2010 - 03:26 AM
Since tableName() is a function you should be able to return any value you want. The logic for that method depends on your requirements...
#3
Posted 19 January 2010 - 04:43 AM
And how to pass parameters to this method?I tried to override constructor but my solution not work.
class Outsite extends CActiveRecord { private $_dsn; private $_username; private $_password; private $_tablename; public function __construct($dsn='',$username='',$password='',$tablename='') { $this->_dsn=$dsn; $this->_username=$username; $this->_password=$password; $this->_tablename=$tablename; parent::__construct(); } public function getDbConnection() { $connection=new CDbConnection($this->_dsn,$this->_username,$this->_password); $connection->active=true; return $connection; } /** * Returns the static model of the specified AR class. * @return CActiveRecord the static model class */ public static function model($className=__CLASS__) { return parent::model($className); } /** * @return string the associated database table name */ public function tableName() { return $this->_tablename; } }
$out=new Outsite($dsn,$username,$password,'user'); $model=$out->findAll();
#5
Posted 19 January 2010 - 04:53 AM
parent::__construct() should be the first call you make, not the last.
#6
Posted 19 January 2010 - 06:16 AM
I get error:
Missing argument 2 for Outsite::__construct(), called in E:\www\UPI\framework\db\ar\CActiveRecord.php on line 326 and defined
Missing argument 2 for Outsite::__construct(), called in E:\www\UPI\framework\db\ar\CActiveRecord.php on line 326 and defined
#7
Posted 19 January 2010 - 06:20 AM
This is my stack trace:
#0 E:\www\framework\db\ar\CActiveRecord.php(326): Outsite->__construct() #1 E:\www\framework\db\ar\CActiveRecord.php(341): model() #2 E:\www\framework\db\ar\CActiveRecord.php(59): Outsite->getMetaData() #3 E:\www\project\protected\models\Outsite.php(37): Outsite->__construct() #4 E:\www\project\protected\controllers\SiteController.php(46): Outsite->__construct() #5 E:\www\framework\web\actions\CInlineAction.php(32): SiteController->actionIndex() #6 E:\www\framework\web\CController.php(300): CInlineAction->run() #7 E:\www\framework\web\CController.php(278): SiteController->runAction() #8 E:\www\framework\web\CController.php(257): SiteController->runActionWithFilters() #9 E:\www\framework\web\CWebApplication.php(320): SiteController->run() #10 E:\www\framework\web\CWebApplication.php(120): CWebApplication->runController() #11 E:\www\framework\base\CApplication.php(135): CWebApplication->processRequest() #12 E:\www\project\index.php(11): CWebApplication->run()
#8
Posted 19 January 2010 - 07:24 PM
I solved the problem by keeping the data in the user session. The solution may be not elegant but works.
#9
Posted 28 March 2013 - 10:33 AM

Sapevi che cercando su google yii2 + "la funzione su cui stai impazzendo", trovi quasi sempre dei buoni indizi in italiano, per risolvere i tuoi problemi, senza perdere tempo a postare?
#10
Posted 29 March 2013 - 03:55 PM
Hi
I've done that in the past though I've run into several issues in the framework
I logged this in the bug tracking system and also opened a forum thread on it.
You can track this back throught the old and new tracking system:
https://code.google....Stars%20Summary
https://github.com/y.../yii/issues/172
Currently I am not using the method for several reasons; one of them is that I do not like changing the framework on each upgrade.
I've done that in the past though I've run into several issues in the framework
I logged this in the bug tracking system and also opened a forum thread on it.
You can track this back throught the old and new tracking system:
https://code.google....Stars%20Summary
https://github.com/y.../yii/issues/172
Currently I am not using the method for several reasons; one of them is that I do not like changing the framework on each upgrade.
Share this topic:
Page 1 of 1