Yii Framework Forum: Define where clause for actionAdmin() - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Define where clause for actionAdmin() Rate Topic: -----

#1 User is offline   dubby 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 144
  • Joined: 10-February 09
  • Location:Melbourne, Australia

Posted 07 July 2010 - 08:59 PM

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.
0

#2 User is offline   fastcrash 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 245
  • Joined: 10-March 10
  • Location:South Jakarta

Posted 08 July 2010 - 01:21 AM

did you mean something like this ?

Add Funtion in Value cgridview
0

#3 User is offline   dubby 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 144
  • Joined: 10-February 09
  • Location:Melbourne, Australia

Posted 08 July 2010 - 02:34 AM

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));

0

#4 User is offline   fastcrash 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 245
  • Joined: 10-March 10
  • Location:South Jakarta

Posted 08 July 2010 - 02:52 AM

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


Quote

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

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.
0

#5 User is offline   dubby 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 144
  • Joined: 10-February 09
  • Location:Melbourne, Australia

Posted 08 July 2010 - 03:08 AM

View Postfastcrash, on 08 July 2010 - 02:52 AM, said:

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


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.
0

#6 User is offline   fastcrash 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 245
  • Joined: 10-March 10
  • Location:South Jakarta

Posted 08 July 2010 - 03:31 AM

Quote

What I want to do is have actionAdmin() pass records for Client where the businessId was equal to 1 for example


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?
0

#7 User is offline   dubby 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 144
  • Joined: 10-February 09
  • Location:Melbourne, Australia

Posted 08 July 2010 - 03:43 AM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users