Disable auto report


I am newbie in Yii thing, sorry for stupid question.

I want to know how can I force page don’t query DB in page load automatically and just query to DB when I hit SEARCH button, Because page takes a long time to open.

I want to CGridView be empty in page open, and then fill when I hit search button.

Thanks in advance.

Oh, this is rather simple. All you need is just do not use CActiveDataProvider/CSqlDataProvider when the search form is not submitted. Considering that CGridView requires an instance of IDataProvider to be rendered you can just pass a dummy CArrayDataProvider. In general terms:

// view file

<?php $this->widget('CGridView', array(

  'dataProvider' => $this->getSearchResultProvider(), // refer to Controller::getSearchResultProvider()

)); ?>

// controller class

class Controller extends CController




   * @return IDataProvider


  public function getSearchResultProvider()


    $searchForm = Yii::app()->getRequest()->getParam('SearchFormModel');

    if ($searchForm === NULL)


      // no data submitted 

      return new CArrayDataProvider(array());




      // search request is received 

      return new CActiveDataProvider('SearchActiveRecord', array(

        // your conditions here





Note, that you can reduce number of sql-queries (for cases of using active record) using schema caching.

Thanks sir.

However i found another way after submitting thread, but i tried this way as well, works like a charm.

Thanks again