2014-11-19 4 views
0

나는 단순한 연도 목록 인 정적 dropDownList가 있습니다. 나는 현재 연도 (PHP에서 날짜()를 사용하여 메신저) 기본값으로 원한다. yii에서 어떻게합니까?yii의 드롭 다운 목록의 기본값

을 heres 내 DROPDOWNLIST 코드 :

<?php echo $form->dropDownList($model,'YEAR', 
      array ('1990' => ... => '2020') 
     ); 

답변

1

그것은 $ 모델에 기본 값을 설정하여 가능합니다. 날짜에 대한

<?php 
    // see http://php.net/manual/en/function.date.php#refsect1-function.date-parameters 
    // for more details about the parameter of date() function. 
    $model->YEAR= date('Y'); 
    // see https://github.com/yiisoft/yii/blob/1.1.15/framework/web/helpers/CHtml.php#L1799 
    // to know how Yii detect selected value. 
    echo $form->dropDownList(
     $model, 
     'YEAR', 
     array (
      '1990' => ..., 
      ... 
      '2020' => ... 
     ) 
    ); 
?> 

() here를보고, 드롭 다운리스트에 대해() here를 참조하십시오.