title: How do I make an option selected in Yii framework
body: <p>This is dropdown: </p>
  
  <pre><code>$cities = array('' =&gt; '-- All --');
  $cities += CHtml::listData(Cities::model()-&gt;findAll(), 'id', 'name');
  echo $form-&gt;dropDownList($model, 'city', $cities, array('class' =&gt; 'edit', 'style' =&gt; 'width:auto', 'onchange'=&gt;'$(document).ready(function(){
      $("#pay").trigger("click");});' ) );
  </code></pre>
  
  <p>I want to make the --All-- option to be selected by default. how can I do that ?</p>
  
  <p>Update: I tried like this :</p>
  
  <pre><code>echo $form-&gt;dropDownList($model, 'city', $cities,  array('options' =&gt; array(''=&gt;array('selected'=&gt;true))), array('class' =&gt; 'edit', 'style' =&gt; 'width:auto', 'onchange'=&gt;'$(document).ready(function(){
      $("#pay").trigger("click");});'));
  </code></pre>
  
  <p>but not working.
  This is the html generated:</p>
  
  <pre><code>&lt;select name="FitnessSubscriber[city]" id="FitnessSubscriber_city"&gt;
  &lt;option value="" selected="selected"&gt;-- All --&lt;/option&gt;
  &lt;option value="1" selected="selected"&gt;Cluj-Napoca&lt;/option&gt;
  &lt;option value="2"&gt;Baia Mare&lt;/option&gt;
  &lt;option value="3"&gt;Iași&lt;/option&gt;
  &lt;option value="5"&gt;Timisoara&lt;/option&gt;
  &lt;option value="6"&gt;Bucuresti&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>UPDATE MODEL:
  This is the city model:</p>
  
  <pre><code>class Cities extends ActiveRecord
  {
  
      public static function model($className=__CLASS__)
      {
          return parent::model($className);
      }
  
  
      public function tableName()
      {
          return 'cities';
      }
  
  
      public function rules()
      {
  
          return array(
              array('name', 'length', 'max'=&gt;45),
  
              array('id, name', 'safe', 'on'=&gt;'search'),
          );
      }
  
      public function relations()
      {
  
          return array(
              'city' =&gt; array(self::BELONGS_TO, 'UserLocations', 'city_id'),
              'locations' =&gt; array(self::HAS_MANY, 'Locations', 'city_id'),
              'users' =&gt; array(self::HAS_MANY, 'Users', 'location_id'),
                          'gyms'=&gt;array(self::HAS_MANY, 'FitnessGym', 'city_id'),
                          'pools'=&gt;array(self::HAS_MANY, 'SwimPool', 'city_id'),
  
          );
      }
  
      public function attributeLabels()
      {
          return array(
              'id' =&gt; 'ID',
              'name' =&gt; 'Name',
          );
      }
  
      public function search()
      {
  
          $criteria=new CDbCriteria;
  
          $criteria-&gt;compare('id',$this-&gt;id);
          $criteria-&gt;compare('name',$this-&gt;name,true);
  
          return new CActiveDataProvider($this, array(
              'criteria'=&gt;$criteria,
          ));
      }
  }
  </code></pre>