ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
1、新建并激活Bundle【AppBundle】 ~~~ php app/console generate:bundle ~~~ `编辑:app/AppKernel.php` ~~~ <?php public function registerBundles() { return array( #…… new AppBundle\AppBundle(), ); } ~~~ 2、新建Admin类 `新建:AppBundle/Admin/OneAdmin.php` ~~~ <?php namespace AppBundle\Admin; use Sonata\AdminBundle\Admin\Admin; use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Show\ShowMapper; class OneAdmin extends Admin { protected $baseRouteName = 'one'; //基础路由名 protected $baseRoutePattern = 'one'; //基础路由 public function createQuery($context = 'list'){ $query = parent::createQuery($context); /* List页面输出数据过滤 $query->andWhere( $query->expr()->eq($query->getRootAlias() . '.my_field', ':my_param') ); $query->setParameter('my_param', 'my_value'); */ return $query; } public function configureListFields(ListMapper $listMapper){ } public function configureDatagridFilters(DatagridMapper $datagridMapper){ } public function configureShowFields(ShowMapper $ShowMapper){ } public function configureFormFields(FormMapper $formMapper){ $formMapper ->add('manys', 'sonata_type_collection', array( 'by_reference' => false, 'mapped' => true, 'modifiable' => false, 'type' => 'text', 'type_options' => array( 'delete' => false ), 'pre_bind_data_callback' => null, 'btn_add' => 'link_add', 'btn_catalogue' => 'SonataCoreBundle', ),array( 'edit' => 'inline', 'inline' => 'table', 'sortable' => 'position', 'admin_code' => 'app.admin.one' //也可以设置在该Admin类服务配置的第一个参数 )); } /* 在对象保存及更新时触发自定义事件 public function saveManys ($object){ foreach($object->getManys() as $many){ $record->setOne($object); } } public function prePersist($object){ $this->saveManys($object); } public function preUpdate($object){ $this->saveManys($object); } */ } ~~~