【发布时间】:2014-01-25 20:37:19
【问题描述】:
我的应用程序通过主机路由处理多个商店,因此几乎每个表都有shop_id。现在,我有类别和单独的表单来通过CategoriesType 管理它们。
$builder->add('categories', 'bootstrap_collection', array(
'type' => $this->categoryType,
'allow_add' => true,
'allow_delete' => true,
'error_bubbling' => false,
));
categoryType 是一个Type,它由当前商店构造,data_class 设置为 Category 实体。但是需要 shop_it 正确存储在数据库中。
问题是,如何在表单验证之前嵌入逻辑来更改对象 - 如何在新实体上使用 setShop()。
这是我的使用方法:
$categoriesForm = $this->createForm(new MenuCategoriesType(
$this->get('form.category_type')
), $catering = $this->getUser()->getCatering());
$categoriesForm->handleRequest($request);
if ($categoriesForm->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($catering);
$em->flush();
}
【问题讨论】: