How to use scenario of an CActiveRecord

Hi friends,

If I want to support use ajax search function in display, I’ll use like actionAdmin():




$model=new LichChay('search');

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['LichChay']))

			$model->attributes=$_GET['LichChay'];

        

		$this->render('admin',array(

			'model'=>$model,

		));



In above code, we use scenario of CActiveRecord is "search" to call function search in model. In model, the search function using criteria to compare each properties.

If my view have a dropdownbox, and user wanna filter data by dropdown and then they also can search. Can I add more than one scenario during call my model (Lichchay) instant of "search"

Thanks

The search function is not called because you specify the "search" scenario (used only for validation purposes). Usually, you manually invoke the search method when you display the search results. GridView example:




$this->widget('zii.widgets.grid.CGridView', array(

	'dataProvider'=>$model->search(),

...

Not too clear what you exactly try to do, but it seems that it can be done by posting all the form fields you use at each ajax request.

Hope this helps!