Php 如何在SonataAdminBundle中添加具有关系的新实体
目前我正在建立一个网络商店,我想在我的系统中管理一些产品。 问题是SonataAdmin不允许我编辑具有关系的两个实体Php 如何在SonataAdminBundle中添加具有关系的新实体,php,symfony,doctrine,sonata-admin,Php,Symfony,Doctrine,Sonata Admin,目前我正在建立一个网络商店,我想在我的系统中管理一些产品。 问题是SonataAdmin不允许我编辑具有关系的两个实体 存在“RFID”实体: “产品”实体: 以及“手机玻璃”实体: Sonata未显示“Sonata_model_type”的产品实体。 以下是管理类: namespace Admin\StorageBundle\Admin; use Sonata\AdminBundle\Admin\Admin; use Sonata\AdminBundle\Datagrid\Datagr
namespace Admin\StorageBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Show\ShowMapper;
class CellPhoneGlassAdmin extends Admin
{
/**
* @param DatagridMapper $datagridMapper
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->tab("Product")
->with("")
->add('product', 'sonata_type_model', array(
'class' => 'Admin\StorageBundle\Entity\Product',
'property' => 'name',
'by_reference' => false,
))
->end()
->end()
->tab("Glass")
->with("")
->add('phone')
->add('model')
->end()
->end()
;
}
/**
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->tab("Product")
->with("")
->add('product', 'sonata_type_model', array(
'class' => 'Admin\StorageBundle\Entity\Product',
'property' => 'name',
'by_reference' => false,
))
->end()
->end()
->tab("Glass")
->with("")
->add('phone')
->add('model')
->end()
->end()
;
}
/**
* @param FormMapper $formMapper
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->tab("Product")
->with("")
->add('product', 'sonata_type_model', array(
'class' => 'Admin\StorageBundle\Entity\Product',
'property' => 'name',
'by_reference' => false,
))
->end()
->end()
->tab("Glass")
->with("")
->add('phone')
->add('model')
->end()
->end()
;
}
/**
* @param ShowMapper $showMapper
*/
protected function configureShowFields(ShowMapper $showMapper)
{
$showMapper
->tab("Product")
->with("Content")
->add('product', 'sonata_type_model', array(
'class' => 'Admin\StorageBundle\Entity\Product',
'property' => 'name',
'by_reference' => false,
))
->end()
->end()
->tab("Glass")
->with("Content")
->add('phone')
->add('model')
->end()
->end()
;
}
}
不确定我是否正确理解了您的需求,我假设您希望从CellPhoneGlass表单添加新产品 您必须使用sonata_type_model_列表来执行此操作,sonata_type_模型只允许选择现有实体:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->tab("Product")
->with("")
->add('product', 'sonata_type_model_list')
->end()
->end()
->tab("Glass")
->with("")
->add('phone')
->add('model')
->end()
->end()
;
}
官方文档:不确定我是否正确理解了您想要的内容,我假设您想要从CellPhoneGlass表单添加新产品 您必须使用sonata_type_model_列表来执行此操作,sonata_type_模型只允许选择现有实体:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->tab("Product")
->with("")
->add('product', 'sonata_type_model_list')
->end()
->end()
->tab("Glass")
->with("")
->add('phone')
->add('model')
->end()
->end()
;
}
正式文件:
namespace Admin\StorageBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Show\ShowMapper;
class CellPhoneGlassAdmin extends Admin
{
/**
* @param DatagridMapper $datagridMapper
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->tab("Product")
->with("")
->add('product', 'sonata_type_model', array(
'class' => 'Admin\StorageBundle\Entity\Product',
'property' => 'name',
'by_reference' => false,
))
->end()
->end()
->tab("Glass")
->with("")
->add('phone')
->add('model')
->end()
->end()
;
}
/**
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->tab("Product")
->with("")
->add('product', 'sonata_type_model', array(
'class' => 'Admin\StorageBundle\Entity\Product',
'property' => 'name',
'by_reference' => false,
))
->end()
->end()
->tab("Glass")
->with("")
->add('phone')
->add('model')
->end()
->end()
;
}
/**
* @param FormMapper $formMapper
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->tab("Product")
->with("")
->add('product', 'sonata_type_model', array(
'class' => 'Admin\StorageBundle\Entity\Product',
'property' => 'name',
'by_reference' => false,
))
->end()
->end()
->tab("Glass")
->with("")
->add('phone')
->add('model')
->end()
->end()
;
}
/**
* @param ShowMapper $showMapper
*/
protected function configureShowFields(ShowMapper $showMapper)
{
$showMapper
->tab("Product")
->with("Content")
->add('product', 'sonata_type_model', array(
'class' => 'Admin\StorageBundle\Entity\Product',
'property' => 'name',
'by_reference' => false,
))
->end()
->end()
->tab("Glass")
->with("Content")
->add('phone')
->add('model')
->end()
->end()
;
}
}
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->tab("Product")
->with("")
->add('product', 'sonata_type_model_list')
->end()
->end()
->tab("Glass")
->with("")
->add('phone')
->add('model')
->end()
->end()
;
}