2012-04-01 122 views
0

我想創建這樣的事情,因爲我已經在我的管理視圖中的一個做它:HTML的幫助postLink CakePHP中

<td class="actions"> 
    <form action="https://stackoverflow.com/users/delete/26" name="post_4f7825317b6b0" id="post_4f7825317b6b0" style="display:none;" method="post"> 
     <input type="hidden" name="_method" value="POST"> 
    </form> 
    <a href="#" onclick="if (confirm('Are you sure you want to delete # 26?')) { document.post_4f7825317b6b0.submit(); } event.returnValue = false; return false;"> 
     Delete 
    </a> 
</td> 

使用此:

<?php 
    echo $this->Form->postLink(__('Delete'), array(
       'action' => 'delete', 
       $user['User']['id']), 
       null, 
       __('Are you sure you want to delete # %s?', $user['User']['id'])); 
?> 

我想它在另一種觀點相同的代碼,我不知道爲什麼我只得到這樣的:

<input type="hidden" name="_method" value="POST"> 
<a href="#" onclick="if (confirm('Are you sure you want to delete # %s?')) { document.post_4f782a44e9784.submit(); } event.returnValue = false; return false;"> 
    Delete 
</a> 

這究竟是爲什麼,如果我使用的是完全相同的合作德生成它? 謝謝。

+0

您確定設置了$ user變量並且包含您認爲它的用途嗎? – JJJ 2012-04-01 11:02:36

+0

是的,我相信它。 – Alvaro 2012-04-01 19:48:32

回答

-4

你還沒有創建表單本身,所以基本上你使用的是沒有表單的輸入字段。

echo $this->Form->create(); 
+4

這實際上是錯誤的。 $ this-> Form-> postLink()不必位於表單內。其實它不能在表單內(見https://github.com/cakephp/cakephp/blob/master/lib/Cake/View/Helper/FormHelper.php#L1728)。 – 2014-02-11 14:25:38

+2

這是如此的誤導......就像@tinytiger指出的那樣,你不能在表單中使用表單。這會破壞事情。 – Timber 2014-04-30 17:59:44

+0

這個答案是絕對錯誤的,應該刪除。 – schnauss 2014-08-16 07:22:25

0

第一。檢查CakePHP版本。

<?php 
    echo $this->Form->postLink(__('Delete'), array(
       'action' => 'delete', 
       $user['User']['id']), 
       ['inline' => true], 
       __('Are you sure you want to delete # %s?', $user['User']['id'])); 
?>