CakePHP 3 自定义模板不适用于按钮元素
CakePHP 3 custom template not working for the button element
我尝试用 <div></div>
围绕按钮元素,如下面的代码所示,但它没有按预期工作。屏幕截图显示了按钮的显示方式。
enter image description here
<?= $this->Form->button('<i class="glyphicon glyphicon-log-in "></i> Sign in', [
'templates' => [
'button' => '<div class="col-xs-4"><button{{attrs}}>{{text}}</button></div>'],
'type' => 'submit',
'class' => 'btn bg-navy btn-flat',
'escape' => false
]);
?>
用 <div></div>
包围按钮元素的正确方法是什么?
Form->button()
方法
没有 templates
选项
您必须在创建输入之前设置模板
<?php
$this->Form->setTemplates([
'button' => '<div class="col-xs-4"><button{{attrs}}>{{text}}</button></div>'])
?>
<?= $this->Form->button('<i class="glyphicon glyphicon-log-in "></i> Sign in',
'type' => 'submit',
'class' => 'btn bg-navy btn-flat',
'escape' => false
]);
?>
请记住,您还可以将模板放在一个文件中,以便在所有表单中使用它们(请参阅说明书 here)
您也可以直接将 html 直接放在您的页面中,根本不使用任何模板 ;-)
<div class="col-xs-4">
<?= $this->Form->button('<i class="glyphicon glyphicon-log-in "></i> Sign in',
'type' => 'submit',
'class' => 'btn bg-navy btn-flat',
'escape' => false
]);
?>
</div>
如果您只需要一种形式的 div 元素,也许您根本不需要模板。
我尝试用 <div></div>
围绕按钮元素,如下面的代码所示,但它没有按预期工作。屏幕截图显示了按钮的显示方式。
enter image description here
<?= $this->Form->button('<i class="glyphicon glyphicon-log-in "></i> Sign in', [
'templates' => [
'button' => '<div class="col-xs-4"><button{{attrs}}>{{text}}</button></div>'],
'type' => 'submit',
'class' => 'btn bg-navy btn-flat',
'escape' => false
]);
?>
用 <div></div>
包围按钮元素的正确方法是什么?
Form->button()
方法
templates
选项
您必须在创建输入之前设置模板
<?php
$this->Form->setTemplates([
'button' => '<div class="col-xs-4"><button{{attrs}}>{{text}}</button></div>'])
?>
<?= $this->Form->button('<i class="glyphicon glyphicon-log-in "></i> Sign in',
'type' => 'submit',
'class' => 'btn bg-navy btn-flat',
'escape' => false
]);
?>
请记住,您还可以将模板放在一个文件中,以便在所有表单中使用它们(请参阅说明书 here)
您也可以直接将 html 直接放在您的页面中,根本不使用任何模板 ;-)
<div class="col-xs-4">
<?= $this->Form->button('<i class="glyphicon glyphicon-log-in "></i> Sign in',
'type' => 'submit',
'class' => 'btn bg-navy btn-flat',
'escape' => false
]);
?>
</div>
如果您只需要一种形式的 div 元素,也许您根本不需要模板。