title: Yii Search in navigation menu
body: <p>I'm currently writing an application in Yii in which i want to create a search box in the header (either in the navigation menu or just above it). This search box should be able to be accessed from every part of the site, and it should be able to search on different columns of different tables.</p>
  
  <p>I have no idea on how to do this, and almost all posts on the web about it involves using the grid-view, or an extension (I'd like to create the code without an extension if that's possible).</p>
  
  <p>Do you have an idea to how the search code should look (what i should put in which controller etc.)?</p>
  
  <p>-- EDIT --</p>
  
  <p>I still don't know how to do this but I will show you what I have at the moment anyway. It is not much and it is pretty obvious where i am missing some code.</p>
  
  <p>/view/layout/main.php:  </p>
  
  <pre><code>&lt;?php echo CHtml::form(Yii::app()-&gt;createUrl('product/search'), 'get') ?&gt;
              &lt;?php echo CHtml::textField('search_key','',array('placeholder' =&gt; 'Search')); ?&gt;
              &lt;?php echo CHtml::submitButton('Go'); ?&gt;
  &lt;?php echo CHtml::endForm() ?&gt;
  </code></pre>
  
  <p>/view/product/search.php:</p>
  
  <pre><code>//Not sure by any means what to write here, but I'll like a list view populated with the search results
  </code></pre>
  
  <p>/controllers/productController.php</p>
  
  <pre><code>/**
   * Search through model.
   */
  public function actionSearch()
  {
      if(isset($_GET['search_key'])){
          $search = $_GET['search_key'];  
          $model-&gt;name = $search;  
      }       
  
      $this -&gt; render('search', array(
          'model' =&gt; $model,
      ));
  }
  </code></pre>
  
  <p>/models/Product.php</p>
  
  <pre><code>/**
   * Retrieves a list of models based on the current search/filter conditions.
   * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
   */
  public function search()
  {
      // Warning: Please modify the following code to remove attributes that
      // should not be searched.
  
      $criteria=new CDbCriteria;
  
      $criteria-&gt;compare('name',$this-&gt;name,true);
  
      return new CActiveDataProvider($this, array(
          'criteria'=&gt;$criteria,
      ));
  }
  </code></pre>