我確定我正在以這種錯誤的方式進行,但我需要從sfWidgetFormChoice中的某個選項中取消設置數組鍵。將該變量賦給表單的唯一方法是從動作中獲取。下面是我有:如何將變量從動作傳遞到形式
操作:
$id = $request->getParameter('id');
$deleteForm = new UserDeleteForm();
$choices = array();
$choices = $deleteForm->getWidgetSchema('user')->getAttribute('choices');
unset($choices[$id]); //I obviously don't want the user to be able to transfer to the user being deleted
$this->deleteForm = $deleteForm;
形式:
$users = Doctrine_Core::getTable('sfGuardUser')->getAllCorpUsers()->execute();
$names = array();
foreach($users as $userValue){
$names[$userValue->getId()] = $userValue->getProfile()->getFullName();
};
// unset($names[$id]); //this works, but I can't figure out how to get $id here.
$this->widgetSchema['user'] = new sfWidgetFormChoice(array(
'choices' => $names
));
$this->validatorSchema['user'] = new sfValidatorChoice(array(
'required' => true,
'choices' => $names
));
你爲什麼要爲它標記symfony2? – cheesemacfly
symfony2用戶以1.4開頭,這是理所當然的。我正在儘可能多地尋找我的問題。 – Patrick
您應該使用[一個賞金](http://stackoverflow.com/help/bounty)。應避免將不相關標籤添加到問題以獲得可見性。 – cheesemacfly