I want to use a single search box to search all the columns in my user table and display the results in a grid. The problem is that I do not know how to get the search post data to the search() method in the user model. I know there must be a simple answer to this problem.
View code:
<div class="search-form">
<div class="wide form">
<?php $form=$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'get',
)); ?>
<div class="row">
<?php echo $form->textField($model_search,'search_string',array('size'=>60,'maxlength'=>128)); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Search'); ?>
</div>
<?php $this->endWidget(); ?>
</div>
</div><!-- search-form -->
<?php
// Display the user grid from user model
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-grid',
'dataProvider'=>$model->search(),
'columns'=>array(
'id',
'username',
'email',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
Search method in the user model. Notice the where my problem is. What goes here?
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('username',<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />,true, 'OR');
$criteria->compare('email',<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />,true, 'OR');
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}