【问题标题】:cant set default options dropdown box无法设置默认选项下拉框
【发布时间】:2014-10-23 13:53:05
【问题描述】:

我已经用数据填充了一个下拉框,我可以从列表中进行选择。我似乎无法将选项设置为所选值。我选择了一个值,我希望下拉框显示最后选择的值而不是重置为列表中的第一个选项。我试过选中,默认有和没有数字。

  public function admin_list($tutorId=0,$paycycleId=0) {

        if (isset($this->request->data['tutor'])) {
          debug($this->request->data['TimeSheet']['tutor']);
          $tutorId=$this->request->data['TimeSheet']['tutor'];
          return $this->redirect(array('action' => 'admin_list',$tutorId,$paycycleId));
      }//isset

  view////
     echo $this->Form->input('paycycle', array('label' => 'Pay Cycle Period',
                    'empty' =>array(0 => 'choose'), 'options' => $pcycle,'default'=>2 ));

          echo $this->Form->submit('Select a Pay Cycle', array('name'=>'paycycle'));
             echo $this->Form->end();

【问题讨论】:

    标签: php cakephp


    【解决方案1】:

    按照CakePHP Book中的详细说明:

    将‘selected’设置为您希望在呈现输入时默认选择的项目的值

    【讨论】:

    • ypu 需要设置的值。 echo $this->Form->input('tutor', array('label' => 'Tutor', 'empty' =>array(0 => 'choose'),'options' => $tutor,'selected ' => $tutorId ));
    猜你喜欢
    • 2019-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-28
    • 1970-01-01
    • 2019-08-13
    • 2014-06-28
    • 2014-12-08
    相关资源
    最近更新 更多