jpr*_*izs 13 html php cakephp cakephp-3.0
我试图删除或更改CakePHP在其表单助手上使用的包装div.
当我使用这段代码时:
echo $this->Form->input('contact', ['label' => false]);
Run Code Online (Sandbox Code Playgroud)
输出是:
<div class="input text">
<input type="text" id="contact" maxlength="255" name="contact">
</div>
Run Code Online (Sandbox Code Playgroud)
而我想要的是:
<div class="myOwnClass">
<input type="text" id="contact" maxlength="255" name="contact">
</div>
Run Code Online (Sandbox Code Playgroud)
我曾经在CakePHP 2上为输入法添加了更多选项,但是在最新的CakePHP版本中这不起作用.有线索吗?
谢谢
小智 30
要更改表单中所有输入的包装使用:
$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
]);
Run Code Online (Sandbox Code Playgroud)
要更改单个输入使用的包装:
echo $this->Form->input('contact', [
'templates' => [
'inputContainer' => '<div class="myOwnClass">{{content}}</div>'
],
'label' => false
]);
Run Code Online (Sandbox Code Playgroud)
有关模板的完整参考,请阅读:自定义模板FormHelper使用
在版本3中不再支持CakePHP 2样式的自定义包装.从迁移指南:
div,before,after,between和errorMessage选项已从input()中删除.您可以使用模板更新包装HTML.templates选项允许您覆盖一个输入的已加载模板.
小智 5
我正在使用购买的UI,并且cakephp3存在一些问题.对我来说<div>,经过大量测试后,删除最初的,最常见的解决方案并不是那么容易:
echo $this->Form->control('username', [
'templates' => ['inputContainer' => '{{content}}'],
"type" => "text",
"aria-invalid" => "false",
"aria-required" => "true",
"class" => "form-control valid",
"placeholder" => "Ingrese su usuario o email ...",
"autocomplete" => "on",
'label' => false
]);
Run Code Online (Sandbox Code Playgroud)
结果
<input name="username" aria-invalid="false" aria-required="true" class="form-control valid" placeholder="Ingrese su usuario o email ..." autocomplete="on" id="username" type="text">
Run Code Online (Sandbox Code Playgroud)
只添加输入标记(对不起我的Google-English)
| 归档时间: |
|
| 查看次数: |
16661 次 |
| 最近记录: |