0
等量我嘗試創建一個customWidget具有特殊tablemethod只顯示用戶的預選的選擇,這是形式:自定義部件不顯示的選擇
$this->widgetSchema['Books_list'] = new MyWidgetFormThematicSelector(array(
'multiple' => true,
'model' => 'Books',
'table_method' => array('method' => 'getOnlySelected', 'parameters' => array($this->getObject()->getId())),
'expanded' => true,
));
這是方法getOnlySelected:
$q = Doctrine::getTable('BooksAuthors')
->createQuery('ba')
->select('ba.position,ba.name')
->leftJoin('ba.Books b')
->where('ba.BooksAuthors_id = ?', $id);
echo count($q); //return 4
return $q;
這個方法返回4個元素這是正常的,然後如果我嘗試從窗口小部件我只得到1回波的getChoices方法的值!?
class MyWidgetFormThematicSelector extends sfWidgetFormDoctrineChoiceWithParams {
public function configure($options = array(), $attributes = array())
{
parent::configure($options, $attributes);
}
public function getChoices() {
$choices = parent::getChoices();
echo count($choices); // return 1
return $choices;
}
public function render($name, $value = null, $attributes = array(), $errors = array()) {
return parent::render($name, $value, $attributes, $errors);
}
}
這是怎麼回事?
創建在該probleme不會出現同樣的形式類似的部件,它個相當相同的代碼...
THX
你有sfWidgetFormDoctrineChoiceWithParams的代碼嗎?沒有看到這個班級是如何工作的,很難說。傳遞的參數是否需要採用鍵/值格式,例如如果傳遞的參數是'parameters'=> array('id'=> $ this-> getObject() - > getId())) – antony 2013-04-29 23:50:52
這裏是類,http://blog.squantin.fr/symfony-1 -4-passer-des-parametres-sur-table_method-dans-un-sfwidgetformdoctrinechoice-4351,我認爲你有正確的想法,但不是將密鑰傳遞給sfWidgetFormDoctrineChoiceWithParams,而是直接從具有key_method屬性的窗體傳遞它。 – krifur 2013-04-30 12:57:45
謝謝,我來看看。它看起來好像這個類有能力返回1條記錄或者它認爲合適的一組記錄。所以我可能會逐步檢查它,看看在這種情況下它是如何做到的。 – antony 2013-04-30 13:01:17