gpt4 book ai didi

php - Cakephp 3.0 更改或删除输入表单上的包装 div

转载 作者:IT王子 更新时间:2023-10-29 00:08:41 24 4
gpt4 key购买 nike

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

当我使用这段代码时:

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

输出是:

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

我想要的是:

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

我曾经在 CakePHP 2 上这样做,向输入法添加更多选项,但是在最新的 CakePHP 版本上这不起作用。有什么线索吗?

谢谢

最佳答案

使用 FormHelper 模板

要更改表单中所有输入的换行,请使用:

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

要更改单输入的换行,请使用:

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

有关模板的完整引用,请阅读: Customizing the Templates FormHelper Uses

版本 3 不再支持自定义包装的 CakePHP 2 样式。来自迁移指南:

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.

关于php - Cakephp 3.0 更改或删除输入表单上的包装 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29686111/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com