【问题标题】:Radio Button CakePHP 3.0单选按钮 CakePHP 3.0
【发布时间】:2015-06-18 00:29:48
【问题描述】:

在 CakePHP 2.0 中,我实际上可以为单选按钮添加“之前”、“之后”和“分隔符”属性。这些属性将在我的单选选项之间创建一个 div 元素。似乎这些选项已从 CakePHP 3.0 中删除。如何在 CakePHP 3.0 中做到这一点?

<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
    <div class="square-screening single-row screen-radio">
      <?php echo $this->Form->input('q1',array(
          'legend'=> false,
          'type'=>'radio',
          'options'=> $options,
          'required'=>'required',
          'before' => '<div class="radio-inline screen-center screen-radio">',
          'separator' => '</div><div class="radio-inline screen-center screen-radio">',
          'after' => '</div>',
      )); ?>
    </div>
</div>

【问题讨论】:

    标签: php cakephp cakephp-3.0


    【解决方案1】:

    您需要使用 FormHelper 模板。来自迁移指南:

    已从 radio() 中删除了分隔符、中间和图例选项。您现在可以使用模板来更改包装 HTML。

    div、before、after、between 和 errorMessage 选项已从 input() 中移除。

    所以在你的情况下使用这个

    echo $this->Form->input('q1', [
        'templates' => [
            'radioWrapper' => '<div class="radio-inline screen-center screen-radio">{{label}}</div>'
        ],
        'type' => 'radio',
        'options' => $options,
        'required' => 'required',
        'label' => false
    ]);
    

    另见:

    【讨论】:

      【解决方案2】:

      这很容易。

      您可以使用表单助手。

      Cake\View\Helper\FormHelper::radio(string $fieldName, array $options, array $attributes)
      

      使用

      echo $this->Form->radio(
          'favorite_color',
          [
              ['value' => 'r', 'text' => 'Red', 'style' => 'color:red;'],
              ['value' => 'u', 'text' => 'Blue', 'style' => 'color:blue;'],
              ['value' => 'g', 'text' => 'Green', 'style' => 'color:green;'],
          ]
      );
      

      Docs

      【讨论】:

      • 嗨,Soft Kitty,我已阅读文档。那是您想要向输入元素添加自定义属性的时候。我的疑问是如何在单选选项之间添加开头的“
        ”和关闭的“
        ”,而不是单选选项中的属性。谢谢。
      • 嗨,丹莉。您可以查看本章文档。 book.cakephp.org/3.0/en/views/helpers/…它使用模板,可以与您的html输入合并。
      猜你喜欢
      • 2011-07-27
      • 1970-01-01
      • 2012-04-30
      • 2011-03-13
      • 2021-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多