如何将类添加到postLink表单 - CakePHP 3.4

时间:2017-06-13 19:27:58

标签: forms cakephp cakephp-3.x cakephp-3.4

是否可以在CakePHP的postLink表单助手创建的隐藏表单中添加一个类?

这是我的代码


    Form->postLink(
        ' ' . __('Delete'),
        ['action' => 'delete', $this->fetch('item')],
        ['confirm' => __('Are you sure you want to delete # {0}?', $this->fetch('item'))
        ,'escape' => false
        ,'title' => __('Delete')
        ,'class' => 'btn btn-danger btn-xs isAction'
        ]) ?>

请注意,我不打算将类添加到创建的链接中。

欢迎任何想法!

1 个答案:

答案 0 :(得分:1)

目前只有一种方式,那就是临时更改formStart模板,类似于以下内容:

// read current template and set the new one
$formStart = $this->Form->getTemplates('formStart');
$this->Form->setTemplates([
    'formStart' => '<form class="hiddenFormClass"{{attrs}}>'
]);

echo $this->Form->postLink(/* ... */);

// set the template back to its previous state
$this->Form->setTemplates([
    'formStart' => $formStart
]);

也可以使用resetTemplates()方法将模板重置为默认状态,但这会重置对任何模板所做的所有可能更改,因此可能更好如上所示安全地玩。

另见