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

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

问题描述

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

我的代码是:

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

它返回:

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

我想要输出如下:

<input type="text" name="mobile" class="form-control" id="mobile">

解决方案

对于 CakePHP 3.0 版本...

... 没有办法只将属性传递给模板.您必须重新定义适当的表单助手模板.

您可以使用例如 FormHelper::templates() 来全局更改它们:

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

或仅用于通过 templates 选项的特定输入:

echo $this->Form->input('mobile', ['模板' =>['输入容器' =>'<div class="col-md-4 input {{type}}{{required}}">{{content}}</div>','inputContainerError' =>'<div class="col-md-4 input {{type}}{{required}} 错误">{{content}}{{error}}</div>'],'类' =>'形式控制','标签' =>错误的]);

另见

从 CakePHP 3.1 开始......

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

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

并使用 templateVars 选项来定义它们的值

echo $this->Form->input('mobile', ['类' =>'形式控制','标签' =>错误的,'模板变量' =>['类' =>'col-md-4']]);

另见

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

My code is:

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

and it returns:

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

I want output like:

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

解决方案

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.

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);

or only for a specific input via the templates option:

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
]);

See also

As of CakePHP 3.1 ...

... 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);

and use the templateVars option to define the values for them

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

See also

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

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