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