Q:

yii framework: how to make search result empty in search form?

Hello i created a separate search form having input box and button.
in my model i want to search products by category wise...
but problem is that when input box is empty and clicking on search buttons it displays all entries from the database table..
controller code is-
class AddController extends Controller
{
public function actionAddsearch()
{
$model_form = new Add("search");
    $attributes = Yii::app()->getRequest()->getPost("Add");
if(!is_null($attributes))
{
$model_form->setAttributes(Yii::app()->getRequest()->getPost("Add"));
}

  $this->render("searchResults", array(
 "model" => $model_form, 
 "models" => $model_form->searchAdd(),

 ));

 }

model code--
class Add extends CActiveRecord
 {
public function searchAdd()
{
        $criteria = new CDbCriteria();

        $criteria->compare("addname", $this->category, TRUE, "OR");
        $criteria->compare("category", $this->category, TRUE, "OR");
        return Add::model()->findAll($criteria);    
}

view code- addsearch.php
   <div class="search-bar">
<?php
   $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
"action"=>$this->createUrl("add/addsearch"),
'type'=>'search',
)
); 

     echo $form->textFieldRow($model,'category');
     echo "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp";
     $this->widget('bootstrap.widgets.TbButton',array(
        'buttonType'=>'submit',
        'type'=>'success',
        'size'=>'large',
        'label'=>'Search For Products   ',
    ));

  $this->endWidget(); 

  ?>
 </div>

searchResults.php
<?php 
  echo "<h4>Results for Your Search</h4>";

   foreach($models as $model):

    $this->beginWidget('bootstrap.widgets.TbDetailView',array(
    'type'=>'bordered condensed',
    'data' => array(
  'Shop Name' =>CHtml::link(CHtml::encode($model->addname),array('add/view','id'=> $model->addid)),
'Category' => $model->category
),
'attributes' => array(array('name' => 'Shop Name', 'label' => 'Name of Shop','value'=>CHtml::link(CHtml::encode($model->addname),
                array('add/view','id'=>$model->addid)),'type'=>'raw'),
array('name' => 'Category', 'label' => 'Category of Shop'),

),
)
);

echo "<br><hr><br>";
$this->endWidget();
 endforeach;

 ?>

what is wrong in the code??
I want to display no any product when text box is empty..
thanks in advance 

A:

change this
if(!is_null($attributes))
{
     $model_form->setAttributes(Yii::app()->getRequest()->getPost("Add"));
}

$this->render("searchResults", array(
      "model" => $model_form, 
      "models" => $model_form->searchAdd(),
      ));

To
if($attributes)
{
     $model_form->setAttributes(Yii::app()->getRequest()->getPost("Add"));
     $this->render("searchResults", array(
           "model" => $model_form, 
           "models" => $model_form->searchAdd(),
           ));
}

