如何在symfony 1.4中保存集合表单

时间:2012-01-29 06:32:06

标签: forms symfony-1.4 propel

我在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
            }

        }
    }

}

1 个答案:

答案 0 :(得分:1)

我最后通过手动处理每个表单而不是试图将这种类型的表单装入symfony 1.x表单框架来进行粗略的黑客攻击。

相关问题