是否可以通過使用FormHelper
的方法postLink
將多個參數傳遞給控制器中的某個操作?CakePHP 2.3.0上的Form-> postLink中的多個參數
我沒有設法通過使用options
陣列。在文檔中沒有很好地規定這個數組允許的值。
這是我tryed:
$this->Form->postLink($staffUser['User']['_name'], array(
'action' => 'subscribe',
array('ticketId' => $ticket['Ticket']['id'], 'userId' => $staffUser['User']['id'])
));
我subscribe
動作看起來是這樣的:
public function subscribe($ticketId, $userId = null){
if ($this->request->is('post')) {
//...
}
}
更新
我剛纔注意到所提供的解決方案創建了另一個問題對我來說。現在
class
停止獲取添加了Ulike我只用一個參數時之前:
$this->Form->postLink($staffUser['User']['_name'], array(
'action' => 'subscribe',
$ticket['Ticket']['id'],
$staffUser['User']['id'],
array('class' => 'demo') //not beind added
));
嘗試保留爲空。如果用戶已經在/ controller/subscribe/TICKETID上,那麼它應該默認使用同一個URL來POST(我沒有使用postLink,但FormHelper的create()方法的行爲方式相同)。如果沒有,那麼你也可以嘗試把它作爲一個純字符串放在第二個參數中,即'/ controller/subscribe/param1/param2'。 – gazareth 2014-10-10 12:22:57
我需要這兩個參數。用戶標識可以是任何用戶標識。如果它是空的,登錄的用戶將訂閱。 – Alvaro 2014-10-10 12:24:06