findall with conditionin dropdown

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 .

Hello,

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

http://www.yiiframework.com/doc/api/1.1/CActiveRecord#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.yiiframework.com/doc/api/1.1/CActiveForm#dropDownList-detail)

…or


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

:)


Company::model()->findAll('status = 1')

is shorter :lol:

By the way this shouldn’t even be in bug discussions :D