2
我無法從數據庫中檢索數據,我已將表用戶加入表family_tree三次。 CdbCommand返回從第一個表(family_tree)中選擇的值罰款,但從第二個和第三個表(用戶)中選擇的數據不返回。CDBCriteria加入不返回第二個和第三個表選擇的數據
表的模式是:
用戶
USER_ID | user_fullname
family_tree
tree_creator_id | tree_user1_id | tree_user2_id
模型/ familytree.php:
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
//$criteria->alias='FamilyTree';
$criteria->select='t.*,A.*,B.*,C.*';
$criteria->join = 'join user A on A.user_id=tree_user1_id
join user B on B.user_id=tree_user2_id
join user C on C.user_id=tree_creator_id';
$criteria->compare('tree_id',$this->tree_id,true);
$criteria->compare('tree_creator_id',$this->tree_creator_id,true);
$criteria->compare('tree_user1_id',$this->tree_user1_id,true);
$criteria->compare('tree_user2_id',$this->tree_user2_id,true);
$criteria->compare('tree_type',$this->tree_type,true);
$criteria->compare('tree_type_name',$this->tree_type_name,true);
$criteria->compare('tree_grey_flag',$this->tree_grey_flag);
//$criteria->join('user', 'tree_creator_id=user.user_id');
//$criteria->compare('tree_user_id',$this->A->user_fullname, true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
視圖/譜系圖/ admin.php的
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'family-tree-grid',
'dataProvider'=>$model->search(),
'columns'=>array(
'tree_id',
'tree_creator_id',
'C.user_fullname',
'tree_user1_id',
'A.user_fullname',
'tree_user2_id',
'B.user_fullname',
'tree_type',
'tree_type_name',
/*'tree_grey_flag',*/
array(
'class'=>'CButtonColumn',
),
),
)); ?>