dropDownList activeForm不显示Yii2中的选定项

时间:2017-05-28 11:16:45

标签: php drop-down-menu yii yii2 active-form

MySql DB中的值:1396-3-6此值无效

1396-03-061379-11-10已合作!!为什么呢?

MySql DB中的字段生日为文字utf8_general_ci

如果有效,请在dropdownlist

中选择我的项目

dropDownList年是工作,但日和月都不起作用

控制器:

# Day
      $days = [];
      for($i=1;$i<=31;$i++)
      {
          $days[$i] = $i;
      }

      # Month
      $month = [
          1 =>  'Fa',
          2 =>  'Or',
          3 =>  'Kh',
          4 =>  'Ti',
          5 =>  'Mo',
          6 =>  'Sh',
          7 =>  'Me',
          8 =>  'Ab',
          9 =>  'Az',
          10 => 'De',
          11 => 'Ba',
          12 => 'Es'];

      # Year
      $year = [];
      $thisYear = General::pDate(time(), 'yyyy');
      for($i=$thisYear;$i>=1360;$i--)
      {
          $year[$i] = $i;
      }

      $birthDate      = explode('-', $model->birthday);
      $birthYear      = ($birthDate[0] < 10) ? substr($birthDate[0], 1) : $birthDate[0];
      $birthMonth     = ($birthDate[1] < 10) ? substr($birthDate[1], 1) : $birthDate[1];
      $birthDay       = ($birthDate[2] < 10) ? substr($birthDate[2], 1) : $birthDate[2];

查看:

<div class="col-xs-3 pull-right selectDay">
            <?= Html::dropDownList('birthday', $birthDay, $days, [
                      'prompt'=> 'Day',
                      'class' => 'form-control',
                  ]) ?>
              </div>

              <div class="col-xs-3 pull-right selectMonth">
                  <?= Html::dropDownList('birthMonth', $birthMonth, $month,[
                            'prompt'=> 'Month',
                            'class' => 'form-control',
                        ]) ?>
              </div>

              <div class="col-xs-3 pull-right selectYear">
                  <?= Html::dropDownList('birthYear', $birthYear, $year,[
                            'prompt'=> 'Year',
                            'class' => 'form-control',
                        ]) ?>
              </div>

1 个答案:

答案 0 :(得分:0)

我有问题。

substr值更改为0表示开始。