0

我正在尝试添加以下样式..

<div class="rowElem noborder">
        <label>Language:</label>
        <div class="formRight noSearch">
          <select name="select2" class="chzn-select">
            <option value="opt1">Choose the Language</option>
            <option value="opt2" selected="selected">Kannada</option>
            <option value="opt3">Telugu</option>
            <option value="opt4">Tamil</option>
          </select>
        </div>
        <div class="fix"></div>
</div>

但是在 cakephp 中,我有这段代码

<?php echo $this->Form->input('language_id', array('class' => 'chzn-select' )); ?>

请给我解决方案..

4

3 回答 3

1

如果我明白你在问什么,这就是你需要做的。

在您的控制器中,您将为选择框创建选项数组:

$this->set('languageOptions', array('opt1' => 'Choose Language', 'opt2' => 'Kannada', 'opt3' => 'Telugu', 'opt4' => 'Tamil'));

然后在视图中创建表单:

<div class="rowElem noborder">
    <label for="language_id">Language:</label>
    <?php echo $this->Form->input('language_id', array('class' => 'chzn-select', 'options' => $languageOptions, 'label' => false, 'div' => array('class' => 'formRight noSearch'))); ?>
    <div class="fix"></div>
</div>
于 2012-04-28T20:26:27.300 回答
0
$langs = array('opt1' => 'Choose Language', 'opt2' => 'Kannada', 'opt3' => 'Telugu', 'opt4' => 'Tamil');

$this->set(compact('langs')); // if you set options from controller

然后在视图中试试这个:

$this->Form->input('language_id', array(
                                      'type' => 'select',
                                      'options' => $langs,
                                      'selected' => 2 // suppose default select Kannada
                                  )
                  );
于 2012-04-30T08:30:24.323 回答
-2

Cake Php 选择选项代码

语言:Form->input('language_id', array('class' => 'chzn-select', 'options' => $languageOptions, 'label' => false, 'div' => array('class' = > 'formRight noSearch'))); ?>
于 2014-10-03T09:09:36.747 回答