Hi all, i just started with yii, re-building a project for learning purposes, Now, I had almost 60 Tables, in 4 databases, and creating a model for each of them would be very tedious and would cost a lot of coffee, so i searched for a way to access all the Tables(all have same structure) in a single database, but i found nothing i could use, so i made this little piece of code that allows me to access different tables, depending upon the url parameter, from a Single Model.
Changes/additions made :
Define a new class(static),
//stat.php in /models
<?php
class stat
{public static $tbName;
public static function SetTbName($param)
{self::$tbName = $param;}
public static function GetTbName()
{ return self::$tbName;}
}
?>
in controller.php
public function actionIndex1()
{
$model=new Stat();
if(isset($_GET['y']))
Stat::SetTbName($_GET['y']);
else Stat::SetTbName('result');
$model=new Result('search');
....
}
in modelName.php
public function tableName()
{
return Stat::GetTbName();
}