I have 2 tables:
CREATE TABLE testbase.author(
id INT (11) NOT NULL AUTO_INCREMENT,
descr VARCHAR (100) NOT NULL DEFAULT ‘<>’,
PRIMARY KEY (id)
)
and
CREATE TABLE testbase.book(
id INT (11) NOT NULL AUTO_INCREMENT,
descr VARCHAR (100) NOT NULL DEFAULT ‘<>’,
author_id INT (11) NOT NULL,
PRIMARY KEY (id)
)
I need to create view for author’s model where his books will be displayed.
In AuthorController i wrote:
public function actionView($id)
{
$bookModel=new Book('search');
$bookModel->unsetAttributes();
if(isset($_GET['Book']))
$bookModel->attributes=$_GET['Book'];
$this->render('view',array(
'model'=>$this->loadModel($id),
'bookModel'=>$bookModel,
'bookDataProvider'=>$bookModel->searchByAuthor($id),
));
}
in Book model:
public function searchByAuthor($author_id_param)
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('descr',$this->descr,true);
$criteria->compare('author_id',$this->author_id);
$criteria->condition='author_id=:author_id';
$criteria->params=array('author_id'=>$author_id_param);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
in view.php (Author) for displaying books I place CGridView:
$this->widget('zii.widgets.grid.CGridView',array(
'dataProvider'=>$bookDataProvider,
'filter'=>$bookModel,
'columns'=>array(
'id',
'descr',
array(
'class'=>'CButtonColumn',
),
)));
Everything is OK except filtering, it doesn’t work and I don’t know why, can anybody help me to solve this issue?