tanimgt
(Tanimgt)
November 18, 2011, 7:12am
1
Hi professional developers, i need to know how could i catch the model data in the filter section of the CGridView, here is my code:
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'users-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'username',
array(
'name'=>'employee_id',
'header'=>'Employee Type',
'value'=>'CHtml::encode($data->employee->employee_type)',
'filter'=>CHtml::listData(Employee::model()->findAll(), 'id', 'employee_type'),
),
array
(
'header'=>'Options',
'class' => 'CButtonColumn',
),
)
));
?>
in the filter section, it shows all employee_type from the database. But i want to set a condition inside the findAll(), like , findAll(array(‘condition’=>‘id=’.$model->employee_id)).
But i cannt retrieve the model data.
Please can any one of you help me ?
Again thanks for reading the post.
kokomo
(Mwerlberger85)
November 18, 2011, 7:23am
2
Working with Database - Reading AR-Record
Employee::model()->findAll('your_column = :your_value', array('your_value'=>123));
tanimgt
(Tanimgt)
November 18, 2011, 7:44am
3
kokomo:
Working with Database - Reading AR-Record
Employee::model()->findAll('your_column = :your_value', array('your_value'=>123));
Many thanks for reply bro,
but i want that values which-es are come from actionAdmin() as $data, like $data->id,
but i cannt retrieve those datas in the filter section of CGridView,.
Thanks
tanimgt
(Tanimgt)
November 19, 2011, 6:56am
4
tanimgt:
Many thanks for reply bro,
but i want that values which-es are come from actionAdmin() as $data, like $data->id,
but i cannt retrieve those datas in the filter section of CGridView,.
Thanks
Ok, i solved like this,
in my views/admin.php->
array(
'name'=>'employee_id',
'header'=>'Employee Name',
'value'=>'CHtml::encode($data->employee->name)',
'filter'=>Users::model()->allemployeeFromThis(),
),
and in my model,
public function allemployeeFromThis() {
$criteria = new CDbCriteria;
$criteria->together = true;
$criteria->with = array('employee');
$criteria->compare('employee.id',$this->employee_id,true);
return CHtml::listData(Users::model()->findAll($criteria), "employee_id", "employee.name");
}
where, employee is my relational table with users.
Hope it can help others. thanks.