我尝试使用特殊的 tablemethod 创建一个 customWidget,以仅显示用户预先选择的选项,这是表单:
$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 个元素,这是正常的,那么如果我尝试从小部件中回显 getChoices 方法的值,我只会得到 1 个作为回报!?
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);
  }
}
这里发生了什么 ?
我以没有出现问题的相同形式创建了一个类似的小部件,并且它的代码完全相同......
谢谢