【问题标题】:Custom templates using 'radioContainer' in Cakephp 3在 Cakephp 3 中使用“radioContainer”的自定义模板
【发布时间】:2014-11-12 14:20:41
【问题描述】:

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

$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

【问题讨论】:

    标签: form-helpers cakephp-3.0


    【解决方案1】:

    我不确定是什么让您认为会有一个名为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>
    

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

    【讨论】:

    • 我使用了可用的版本here。我应该更新它吗?
    • 更新到最新的开发版本,抛出错误 = > 错误:无法找到小部件类“Cake\View\Widget\BasicWidget”
    • @G.J 我无法帮助您解决该错误,至少在没有看到确切的堆栈跟踪和相关代码的情况下不能帮助您,这也可能是新问题。请使用全新的 CakePHP 安装尝试您的表单代码。
    • 我通过更新到最新版本解决了这个问题。感谢拍摄!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多