-1

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

这是我的代码

    表单->postLink(
        ' ' 。__('删除'),
        ['action' => 'delete', $this->fetch('item')],
        ['confirm' => __('你确定要删除#{0}吗?', $this->fetch('item'))
        ,'转义' => 假
        ,'标题' => __('删除')
        ,'class' => 'btn btn-danger btn-xs isAction'
        ]) ?>

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

欢迎任何想法!

4

1 回答 1

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(),但是这将重置对任何模板所做的所有可能更改,因此最好如上所示安全地进行操作。

也可以看看

于 2017-06-14T14:36:39.053 回答