yii-1.1.7.r3135 on apache 2.2 under linux, with php5.3.5 and mysql 5.5.51
customizing a CGridView display to use relational criteria can’t get the search box to show for the relational criteria.
I have searched the wiki and the forums and read many many posts on this subject and tried all suggested remedies but can’t get the search box to show above the relational column although the data for that column shows just fine.
The admin view:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'position-member-links-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
array(
'filter'=>Positions::model(),
'name'=>'Position',
'value'=>'$data->position->position_title',
'type'=>'text',
'header'=>'Pozz',
),
'seat_id',
'member_id',
'from_when',
'to_when',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
controller:
class PositionMemberLinksController extends Controller
{
...
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('PositionMemberLinks', array(
'criteria'=>array(
'with'=>array('member','position'),
)
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
public function actionAdmin()
{
$model=new PositionMemberLinks('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['PositionMemberLinks']))
$model->attributes=$_GET['PositionMemberLinks'];
$this->render('admin',array(
'model'=>$model,
));
}
the model:
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('position_id, member_id', 'required'),
array('position_id, seat_id, member_id', 'numerical', 'integerOnly'=>true),
array('from_when to_when','date','format'=>'yyyy-M-d H:m:s'),//'allowEmpty' defau
lts to true
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, position_title, seat_id, member_id, from_when, to_when', 'safe', 'on'=
>'search'),
);
}
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'member'=>array(self::HAS_ONE,'Members','',
'on'=>'t.member_id=member.id',
),
'position'=>array(self::HAS_ONE,'Positions','',
'on'=>'t.position_id=position.id'),
);
}
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->with=array('member','position');
$criteria->compare('id',$this->id);
$criteria->compare('position_title',$this->position->position_title);
$criteria->compare('seat_id',$this->seat_id);
$criteria->compare('member_id',$this->member_id);
$criteria->compare('from_when',$this->from_when,true);
$criteria->compare('to_when',$this->to_when,true);
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
));
}
The relational data shows correctly in the position column but no search box shows above it, and the other search boxes show. No errors displayed.
Bound to be something simple but it has me beat. Thanks for your help.