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);
}
*/
}
~~~
- 安装
- 配置
- web服务器
- DependencyInjection
- Serializer
- Ajax
- Annotation
- Controller
- Entity
- Components【组件】
- HttpFoundation【HTTP处理】
- Routing【路由处理】
- Form【表单处理】
- Validator【验证处理】
- ClassLoader【类加载】
- Templating【模板】
- Security【处理安全问题】
- Translation【语言翻译】
- Bundles【功能包】
- Doctrine
- entityManager
- entityRespository
- createQueryBuilder
- createNativeQuery
- find
- DoctrineBundle
- doctrine_config
- DoctrineFixturesBundle
- KnpMenuBundle
- KnpPaginatorBundle
- FOSUserBundle
- FOSRestBundle
- FOSCommentBundle
- FOSElasticaBundle
- SonataCoreBundle
- SonataBlockBundle
- SonataMediaBundle
- SonataAdminBundle
- DoctrineORMAdminBundle
- Sonata
- Install_Sonata
- Config_Sonata
- BlockService
- Custom_BlockService
- Custom_Admin
- Problems