Yii Framework Forum: findall with conditionin dropdown - Yii Framework Forum

Jump to content

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

findall with conditionin dropdown Rate Topic: -----

#1 User is offline   vrooomm 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 13-July 12

Posted 03 August 2012 - 03:53 PM

hi ..
i have a drop down list and i use the fuction to findall() to find all the company names is the database .
what i want to do is show only the company's with status=1

please help in what do i change to do so . how to use condition with findall() function ..
thanks a lot .
0

#2 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,165
  • Joined: 05-January 12
  • Location:Morocco

Posted 03 August 2012 - 08:34 PM

Hello,

Yii API doc and the forum's search feature are your friends :)

http://www.yiiframew...#findAll-detail

Now, your answer in the case of an CActiveForm:
            echo $form->dropDownList($model, 'countryId',
                                     CHtml::listData(Company::model()->findAll(array('condition' => 'status = :status', 'params' => array(':status' => 1))), 'id', 'name'),
                                     array('empty' => 'Please select a company »')
                                    );

or

            echo $form->dropDownList($model, 'countryId',
                                     CHtml::listData(Company::model()->findAll('status = 1'), 'id', 'name'),
                                     array('empty' => 'Please select a company »')
                                    );


(you can also see here: http://www.yiiframew...DownList-detail)
1

#3 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 773
  • Joined: 02-July 10
  • Location:Central Poland

Posted 07 August 2012 - 08:09 AM

...or
Company::model()->findAllByAttributes( array( 'status'=>1 ) )

:)
red
1

#4 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,165
  • Joined: 05-January 12
  • Location:Morocco

Posted 07 August 2012 - 09:09 AM

View Postredguy, on 07 August 2012 - 08:09 AM, said:

...or
Company::model()->findAllByAttributes( array( 'status'=>1 ) )

:)


Company::model()->findAll('status = 1')
is shorter :lol:
0

#5 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,165
  • Joined: 05-January 12
  • Location:Morocco

Posted 07 August 2012 - 09:12 AM

By the way this shouldn't even be in bug discussions :D
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