在我的CakePhp应用程序中,我可以这样做:
php echo $this->Form->postLink(
__('Delete'),
array('action' => 'delete', $profile['Profile']['id']),
null,
__('Are you sure you want to delete # %s?', h($profile['Profile']['id']))
);
如何在Twig模板中执行此操作? Twig有数组和哈希,而不是像php那样的组合。我尝试过一些东西,但都没有。例如:
{{ form.postLink('Delete', {
0: 'Delete',
1:{'action' : 'delete'},
2:profile.Profile.id,
3: null,
4: 'Are you sure you want to delete # %s?'
})|raw }}
输出
<form action="/profiles/delete/Delete/1/Are%20you%20sure%20you%20want%20to%20delete%20%23%20%25s%3F" name="post_517f774917df0" id="post_517f774917df0" style="display:none;" method="post">
<input type="hidden" name="_method" value="POST">
<input type="hidden" name="data[_Token][key]" value="69a1fb32b5053ddcbd12d081d4dc605af08390f6" id="Token1914918161"><div style="display:none;">
<input type="hidden" name="data[_Token][fields]" value="12666feca81d6828a076c501deb1385ecb4da673%3A" id="TokenFields1772319507">
<input type="hidden" name="data[_Token][unlocked]" value="" id="TokenUnlocked1920025967">
</div>
</form>
<a href="#" onclick="document.post_517f774917df0.submit(); event.returnValue = false; return false;">Delete</a>
工作确认链接如下所示:
<a href="#" onclick="if (confirm('Are you sure you want to delete # 8?')) { document.post_517f77f0acddb.submit(); } event.returnValue = false; return false;">Delete</a>
答案 0 :(得分:0)
我想你想写下一行
{{ form.postLink('Delete', {'action':'delete', profile.Profile.id}, null, __('Are you shure you want delete # %s?', profile.Profile.id) }}
但是这段代码不起作用。 尝试以下行
{{ form.postLink('Delete', {'action':'delete', 0:profile.Profile.id}, null, 'Are you sure you want to delete #' ~ user.User.id ~ '?' | trans) }}
例如:
array('foo1'=>'bar1', 'aaa', 'foo2'=>'bar2', 'bbb')
转换为树枝
{'foo1':'bar1', 0:'aaa', 'foo2':'bar2', 1:'bbb' }