0

在我的 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>
4

1 回答 1

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' }
于 2013-06-28T02:37:03.013 回答