【问题标题】:how to save a collection form in symfony 1.4如何在 symfony 1.4 中保存集合表单
【发布时间】:2012-08-23 02:13:52
【问题描述】:

我在 symfony 1.4 和 Propel 1.5 中创建了一个集合表单,一切正常显示,但我无法将表单保存到数据库中。

表单用于一次编辑多个用户。

我发现了这个问题,并实施了使用 sfFormPropel 扩展我的 collectionForm 类的建议,但是当我这样做时,我的内存不足。我找不到从数据库中提取的会填满进程内存的内容。

在我的新保存功能中,我什至什么都没做。

有什么想法吗?

class ContactCollectionForm extends sfFormPropel
{
    public function getModelName()
    {
        return 'ContactCollectionForm';
    }

    public function retrieveSubObject($fieldname, $model)
    {
        switch($fieldname)
        {
            default:
                break;
        }
        return array();     
    }

    public function save($con = null)
    {

    }

    public function configure()
    {
        $user           = $this->getOption('user');
        $embedded       = $this->getOption('embedded');
        $custom         = $this->getOption('custom');
        $contact_list   = $this->getOption('contact_list');
        $cf             = $custom['form'];

        if(!array_key_exists(0, $cf['fields']['field']))
            $cf['fields']['field']  = array($cf['fields']['field']);

        $use_fields     = array();

        for($i=0;$i<count($contact_list);$i++)
        {
            foreach($cf['fields']['field'] as $field)
            {
                if($field['type'] == 'object')
                {
                    // embed object form (ala: PersonData, Coordinate etc...)
                    $model      = $field['model'];
                    $model_form = $model.'Form';

                    $sub_object = $contact_list[$i];

                    $sub_form   = new $model_form($sub_object, array('user' => $user, 'embedded' => true, 'custom' => $field['fields']));
                    $this->embedForm($field['name'], $sub_form);
                    array_push($use_fields, $field['name']);

                }   // end field type == object
                else
                {
                    // standard form field
                    $this->setWidget($field['name'], CustomWidgetExtender::createSfWidget($field, $user, $this));
                    $this->widgetSchema->setLabel($field['name'], $field['label']);

                    if(trim($field['default']) != '')
                        $this->setDefault($field['name'], $field['default']);

                    // add field name to use_fields array
                    array_push($use_fields, $field['name']);                
                }   // end field type != object
            }

        }
    }

}

【问题讨论】:

    标签: forms symfony-1.4 propel


    【解决方案1】:

    我最终做了一个粗略的修改,手动处理每个表单,而不是试图将这种类型的表单硬塞到 symfony 1.x 表单框架中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-03
      • 1970-01-01
      相关资源
      最近更新 更多