Hi everybody!
This is my first post and, in my case, that means I completely newbie in Yii world.
My problem is that I’m not able to filter a CGridView (created with Gii) using an external DropDownList. In the table ‘mytable’ there is a field date named ‘mydate’ but I need to filter just by the year. So I create a DropDownList with all the years in the datebase, being selected the present year, and when a new year y selected it has to change the data of the CGridView.
In my views/admin.php I’ve the DropDownList:
<?php
$dateArray = CHtml::listData(Registros::model()->findAllBySql('SELECT mydate FROM mytable group by year(mydate)'),'year','year');
echo CHtml::DropDownList('year_list', date('Y'), $dateArray);
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'mytable-grid',
...
?>
In my models/Mytable.php I have the function to return the year:
public function getYear()
{
$date_field = DateTime::createFromFormat('Y-m-d',$this->mydate);
return $date_field->format('Y');
}
But I’ve no idea how can I use the selected value in the controller and the model to filter the values of my CGridView by year.
Can anybody post me any idea, please? Thanks.