0

我在 listForm.class.php 中的部分代码:

public function configure() {
    $list_id = $this->getOption('list_id');
    $endkunde_id = $this->getOption('endkunde_id');
    $shopname_id = 1;


    $todoWrapperForm = new sfForm();
    $todoWrapperForm = new sfForm();
    //$todos = Doctrine_Core::getTable('Todo')->findAll();


    //$todos = Doctrine_Core::getTable('EinkaufslisteElemente')->findAll();
    $todos = Doctrine_Core::getTable('EinkaufslisteElemente')
            ->createQuery('ee')
            ->where('ee.einkaufsliste_id = ?', $list_id)
            ->innerJoin('ee.Einkaufsliste e')

            ->andWhere('e.shopname_id = ?', $shopname_id)
           ->innerJoin('e.EinkaufslisteEndkunde ek')
            ->execute();


    foreach ($todos as $todo) {
        $todoWrapperForm->embedForm($todo->getId(), new EinkaufslisteElementeForm($todo));
    }
    $todoWrapperForm->embedForm('new_1', new EinkaufslisteElementeForm());  // add one blank todo to start
    $this->embedForm('todos', $todoWrapperForm);


        $this->list =  new sfWidgetFormTextarea(array(), array('rows' => '10', 'cols' => '35'));

    $this->mergePostValidator(new sfValidatorDoctrineUnique(array('model'=>'todo', 'column'=>'task'), array('required' => false)))               ;
    $this->widgetSchema->setNameFormat('todo_list[%s]');
}

我想从“客户”创建一个额外的字段,他的名字没有隐藏,我想创建一个输入字段,用表“列表”中的 list_id 隐藏。如何使用 embedForm 做到这一点?

4

1 回答 1

2

在您的内部listForm,只需在您的配置底部添加:

$this->widgetSchema['list_id']    = new sfWidgetFormInputHidden();
// do not forget to add the propel validator (ie: the one that can check if `list_id` is ok - like in the database)
$this->validatorSchema['list_id'] = new sfValidatorPass();

然后,在您的操作中,不要忘记将默认设置为list_id

$form = new listForm();
$form->setDefault('list_id', $list_id);
于 2012-07-12T14:31:13.127 回答