Yii Framework Forum: How to set the default value for activeDropDownList - Yii Framework Forum

Jump to content

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

How to set the default value for activeDropDownList Rate Topic: -----

#1 User is offline   holala 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 74
  • Joined: 23-December 09

Posted 18 January 2010 - 05:28 AM

hi,

I have a activeDropDownList in my view,

<div class="row">
<?php echo CHtml::activeLabelEx($model,'status'); ?>
<?php echo CHtml::activeDropDownList($model,'status',Survey::getStatusOptions()); ?>
<?php echo CHtml::error($model,'status'); ?>
</div>


getStatusOptions is funciton in my model
class Survey extends CActiveRecord
{
    const STATUS_UNPUBLISH=0;
    const STATUS_PUBLISH=1;
    const STATUS_DRAFT=2;

    ...
    public function getStatusOptions()
    {
        return array(self::STATUS_UNPUBLISH=>'Unpublished',self::STATUS_PUBLISH=>'Published',self::STATUS_DRAFT=>'Draft');
    }
}


how to set option 'Draft' is default for activeDropDownList?

Thank you!
0

#2 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 18 January 2010 - 05:50 AM

As you use the active version of DropDownList, it will be connected to your model attribute. So you can set the default value in your model by adding this:

public $status=self::STATUS_DRAFT;

1

#3 User is offline   holala 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 74
  • Joined: 23-December 09

Posted 18 January 2010 - 06:59 AM

thank you!
thank you!
it's work!
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