我試圖在一個CGridView顯示兩個數據庫表源.. 2桌子是reg.students和login.user .. 我的學生模型關係,如何從兩個數據庫
public function relations()
{
Yii::app()->getModule('user');
return array(
'royaltyOutstandings' => array(self::HAS_MANY, 'RoyaltyOutstanding', 'studentID'),
'srkMedicalInfos' => array(self::HAS_MANY, 'SrkMedicalInfo', 'studentID'),
'parents' => array(self::HAS_ONE, 'SrkParents', 'studentID'),
'srkStudentWorksheets' => array(self::HAS_MANY, 'SrkStudentWorksheet', 'studentID'),
'user' => array(self::BELONGS_TO, 'User', 'centre_id'),
);
}
在用戶模塊中,
public function tableName()
{ return 'login.user'; }
在cgridview列陣列
,
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'students-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'header' => 'No.',
'value' => '$row+1',
),
array('name' => 'user.centre_id',
'value'=>'$data->user->centre_id',
),
'... // & so on
控制器動作,
public function actionAdmin()
{
$this->layout = 'column3';
$form = new Reports ;
$model=new Students('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Students']))
$model->attributes=$_GET['Students'];
$this->render('admin',array(
'model'=>$model,
'form'=>$form,
));
}
http://www.yiiframework.com/doc/api/1.1/CArrayDataProvider - 它可以提供任何你想從任何數據源你想要的數據 –
@RuslanPolutsygan,thnx爲你的信息.. letme檢查這個鏈接n回頭再次回來 –
我可以有兩個數據庫之間的連接示例代碼 –