0

我的默认收音机输入是这样的

$this->Form->radio('email_notifications', ['one','two']);

我默认有这个:

<input type="radio" id="usertype-0" value="0" name="userType">
<label for="email-notifications-0">one</label>

并且需要将这个结构改写为:

<label class="radio" for="usertype-0">
    <input type="radio" id="usertype-0" value="0" name="userType">one
</label>

曾尝试使用自定义模板。它适用于“inputContainer”,但不适用于“radioContainer”。通过为单选按钮添加一个 div 来使用以下内容进行测试:
$this->Form->templates([ 'radioContainer' => '<label {{attrs}}">{{input}}{{text}}</div>' ]);
但对我来说没有任何用处,因为我只得到默认结构。我做错了吗?我也尝试参考这个进行配置:Cakephp 3 multiple custom template formhelpers

4

1 回答 1

0

我不确定是什么让您认为会有一个名为 的模板radioContainer,也许这存在于早期版本中?与单选元素相关的模板是radioradioWrapper

无论如何,默认输出看起来与您所显示的不同,默认情况下单选元素嵌套在标签元素中,即根据您的示例代码正是您正在寻找的内容。

$this->Form->radio('email_notifications', ['one','two']);

将生成以下 HTML(我添加的缩进和换行符)

<input type="hidden" name="email_notifications" value="">
<label for="email-notifications-0">
    <input type="radio" name="email_notifications" value="0" id="email-notifications-0">one
</label>
<label for="email-notifications-1">
    <input type="radio" name="email_notifications" value="1" id="email-notifications-1">two
</label>

所以修复应该是更新到最新的(开发)版本。

于 2014-11-12T14:38:41.563 回答