Hi, I have some problems with CGridview, I’v created a search that searches through two relational tables (that works).
First of all, the CGridview is only showing 3 rows per page but it’s set at showing 10, when I do the search it shows 5 rows per page, and on some pages it shows only one.
Second problem is when I implement a standard search(a search in the current model), it provides a query-error.
When I remove the “with” in the search() function, everything is back to normal (but ofcourse the relational search doesn’t work).
Is there any obvious errors in my code?
Model:
public $author_search;
public function rules()
{
return array(
array('..., author_search', 'safe', 'on'=>'search'),
);
}
public function relations()
{
return array(
'authorgroup' => array(self::HAS_MANY, 'AuthorGroup', 'author_id')),
);
}
public function search()
{
$criteria=new CDbCriteria;
$criteria->with = array('authorgroup'=>array('together'=>true,'with'=>'author'));
$criteria->compare('author.name',$this->author_search,true);
$criteria->compare('post_title',$this->post_title,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>array(
'defaultOrder'=>'t.post_title ASC',
'attributes'=>array(
),
),
));
}
And this is in the _search:
<?php echo $form->label($model,'author_search'); ?>
<?php echo $form->textField($model,'author_search'); ?>
<?php echo $form->label($model,'post_title'); ?>
<?php echo $form->textField($model,'post_title'); ?> //<--------------THIS IS NOT WORKING