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.
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:
// 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());
}
else
{
// 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.