Cakephp 3.0更改或删除输入表单上的包装div [英] Cakephp 3.0 change or remove wrapping div on input form

查看:98
本文介绍了Cakephp 3.0更改或删除输入表单上的包装div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我使用这个代码时:

我尝试删除或更改CakePHP在其表单助手上使用的包装div。

  echo $ this-> Form-> input('contact',['label'=> false]); 

输出为:

 < div class =input text> 
< input type =textid =contactmaxlength =255name =contact>
< / div>

我想要的是:

 < div class =myOwnClass> 
< input type =textid =contactmaxlength =255name =contact>
< / div>

我在CakePHP 2上这样做,为输入法添加更多选项,但是最新的CakePHP版本这不工作。任何线索?



感谢

解决方案

使用FormHelper模板



要在表单中更改所有输入的包装,请使用:

  $ this-> Form-> templates([
'inputContainer'=>'< div class =myOwnClass> {{content}}< / div>'
]);
//或完全删除
$ this-> Form-> templates([
'inputContainer'=>'{{content}}'
]
//现在得到所需包装的输入
echo $ this-> Form-> input('contact',[
'label'=> false
] ;

要更改单输入的包装:

  echo $ this-> Form-> input('contact',[
'templates'=> [
'inputContainer'=>'< div class =myOwnClass> {{content}}< / div>'
],
'label'=> false
] );

有关模板的完整引用,请阅读: 自订范本FormHelper使用



CakePHP 2自定义封装的样式在版本3中不再受支持。从迁移指南:


,after,between和errorMessage选项已从$($)
中删除。您可以使用模板更新换行
HTML。 templates选项允许您为一个输入覆盖已加载的模板



I am trying to remove or change the wrapping div that CakePHP uses on its form helper.

When I use this code:

 echo $this->Form->input('contact', ['label' => false]);

The output is:

<div class="input text">
  <input type="text" id="contact" maxlength="255" name="contact">
</div>

And what I want is:

<div class="myOwnClass">
  <input type="text" id="contact" maxlength="255" name="contact">
</div>

I used to do that on CakePHP 2 adding more options to the input method, however on the latest CakePHP version this isn't working. Any clues?

Thanks

解决方案

Use FormHelper Templates

To change wrapping for all inputs in form use:

$this->Form->templates([
    'inputContainer' => '<div class="myOwnClass">{{content}}</div>'
]);
// or remove completely
$this->Form->templates([
    'inputContainer' => '{{content}}'
]);
// now get input with desired wrapping
echo $this->Form->input('contact', [
    'label' => false
]);

To change wrapping for single input use:

echo $this->Form->input('contact', [
    'templates' => [
        'inputContainer' => '<div class="myOwnClass">{{content}}</div>'
    ],
    'label' => false
]);

For complete reference on templates read: Customizing the Templates FormHelper Uses

CakePHP 2 style of customizing the wrappings is not supported anymore in version 3. From migration guide:

The div, before, after, between and errorMessage options have been removed from input(). You can use templates to update the wrapping HTML. The templates option allows you to override the loaded templates for one input.

这篇关于Cakephp 3.0更改或删除输入表单上的包装div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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