Define where clause for actionAdmin()

Hi all,

I’m sure that this is simple but I can’t find an answer. I have a generic model called Clients for which I am viewing the records with client/admin. However I want to apply a WHERE clause to only return records where an attribute is a given value. I’m not sure what or where I need to make this change. Is it a change I need to make inside the actionAdmin() or elsewhere?

Thanks.

did you mean something like this ?

Add Funtion in Value cgridview

Thanks for the reply.

I have read the post but am still lost on how to achieve this. I don’t want to change anything in the view. I believe I should be able to filter the results in the model or controller for the given attribute.

Can I not do something in the method actionAdmin() like this?




		$model=new Client('search');

		$model = $model->findAll(array('condition'=>'parent_id_spesialis='. $value));



sory #dubby i dont get what you mean, :P

if you want to filter result in cgridview do it in the model




	public function search()

	{

	

		$criteria=new CDbCriteria;


		$criteria->compare('ID_Spseialis',$this->ID_Spseialis);

	

		$criteria->condition='parent_id_spesialis=\''.$value.'\'';

	

		return new CActiveDataProvider('Client', array(

			'criteria'=>$criteria,

			

                        //'pagination'=>array(

                        //           'pageSize'=>self::PAGE_SIZE

                        //  ),


			'sort'=>array('defaultOrder'=>'parent_id_spesialis ASC')

		));

	}



my post before to return result in each row.

OK, I have to be more specific. Using the term filter was not a good example as you can filter the results within the view.

From the start:

By default, the actionAdmin() method will return all results for the given model and then pass these results to the view to be displayed. For this model (Client) there is one attribute named businessId. What I want to do is have actionAdmin() pass records for Client where the businessId was equal to 1 for example. I am retrieving the value OK but I don’t know how or where to implement the condition.

I hope this makes it clearer.

so you want default the actionAdmin() method will return all results with businessId was equal to 1 ?

if so you can do this




        public function search()

        {

                $criteria=new CDbCriteria;


                $criteria->condition='businessId = 1';

                return new CActiveDataProvider('Client', array(

                        'criteria'=>$criteria,

                ));

        }



if not where did you get param ‘OK’ from?

is it from search form?

Thanks fastcrash, that did it.

I thought the search method was only for search or advanced search when in the view. I didn’t realise you can use it to do what I wanted. That search method wasn’t available in the version of Yii that I had been using previously. I must look into that.

Dubby.