在CakePHP 3.0.0中输入包装器div类 [英] Input wrapper div class in CakePHP 3.0.0

查看:176
本文介绍了在CakePHP 3.0.0中输入包装器div类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在CakePHP 3.0.0中更改输入包装器的div类。

How can I change input wrapper div class in CakePHP 3.0.0.?

我的代码是:

<?= $this->Form->input('mobile',['div'=>['class'=>'col-md-4'],'class'=>'form-control','label'=>false]) ?>

并返回:

<div class="input text">
    <input type="text" name="mobile" div="col-md-4" class="form-control" id="mobile">
</div>

我想输出如下:

<div class="col-md-4">
    <input type="text" name="mobile" class="form-control" id="mobile">
</div>


推荐答案

对于CakePHP 3.0版本...



...没有办法只将属性传递给模板。

For CakePHP 3.0 versions ...

... there is no way to just pass on attributes to a template. You'd have to redefine the appropriate form helper templates.

您可以通过使用例如 FormHelper :: templates()

You can either change them globally by using for example FormHelper::templates():

$myTemplates = [
    'inputContainer' => '<div class="col-md-4 input {{type}}{{required}}">{{content}}</div>',
    'inputContainerError' => '<div class="col-md-4 input {{type}}{{required}} error">{{content}}{{error}}</div>'
];
$this->Form->templates($myTemplates);

或仅通过模板选项:

echo $this->Form->input('mobile', [
    'templates' => [
        'inputContainer' => '<div class="col-md-4 input {{type}}{{required}}">{{content}}</div>',
        'inputContainerError' => '<div class="col-md-4 input {{type}}{{required}} error">{{content}}{{error}}</div>'
    ],
    'class' => 'form-control',
    'label' => false
]);

另请参阅

...你可以使用所谓的模板变量。您可以将它们放置在模板中的任何位置

... you can use so called template variables. You can placed them anywhere in a template

$myTemplates = [
    'inputContainer' => '<div class="input {{class}} {{type}}{{required}}">{{content}}</div>',
    'inputContainerError' => '<div class="input {{class}} {{type}}{{required}} error">{{content}}{{error}}</div>'
];
$this->Form->templates($myTemplates);

并使用 templateVars 选项值

echo $this->Form->input('mobile', [
    'class' => 'form-control',
    'label' => false,
    'templateVars' => [
        'class' => 'col-md-4'
    ]
]);

另请参阅

这篇关于在CakePHP 3.0.0中输入包装器div类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆