composer require "zk2/admin-panel-bundle:dev-master"  // app/AppKernel.php public function registerBundles() { return array( // ... new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(), // ... ); }  // app/AppKernel.php public function registerBundles() { return array( // ... new Braincrafted\Bundle\BootstrapBundle\BraincraftedBootstrapBundle(), // ... ); }  # app/config/config.yml ....... # Assetic Configuration assetic: debug: "%kernel.debug%" use_controller: false bundles: [ ] filters: #   node less: node: /usr/bin/node #     $ whereis node node_paths: [/usr/lib/node_modules] # $ whereis node_modules apply_to: "\.less$" cssrewrite: ~ braincrafted_bootstrap: less_filter: less jquery_path: %kernel.root_dir%/../web/js/jquery-1.11.1.js #   jQuery  php app/console braincrafted:bootstrap:install php app/console assetic:dump  // app/AppKernel.php public function registerBundles() { return array( // ... new Zk2\Bundle\AdminPanelBundle\Zk2AdminPanelBundle(), // ... ); }  # app/config/config.yml ...... twig: ...... form: resources: - "Zk2AdminPanelBundle:AdminPanel:bootstrap_form_div_layout.html.twig" #     zk2_admin_panel: check_flag_super_admin: false # --  true,       "flagSuperAdmin()",    pagination_template: Zk2AdminPanelBundle:AdminPanel:pagination.html.twig # -    sortable_template: Zk2AdminPanelBundle:AdminPanel:sortable.html.twig # -         php app/console asset:install web --symlink  namespace AppBundle\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Zk2\Bundle\AdminPanelBundle\AdminPanel\AdminPanelController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class DefaultController extends AdminPanelController { /** * Constructor */ public function __construct() { parent::__construct('AppBundle\Entity\Model','m'); }   /** * listAction * * @Route("/", name="model_list") * * @return renderView */ public function listAction( Request $request ) { //      //  isZk2Granded      //   app/config.yml  zk2_admin_panel.check_flag_super_admin == true, //    " " /* if ( false === $this->isZk2Granded(array('ROLE_LIST')) ) { throw new AccessDeniedException(); }*/ //     if( $this->isReset() ) { return $this->redirect( $this->generateUrl( $this->get('request')->get('_route') ) ); } //    $this->buildListFields(); //        $items = $this->getListFields(); //   $this->getEm()->buildQuery(); //         -- "m,b,c" , //       -- "b.id AS brand_id,b.name AS brand_name,m.name,m.color" //   ,        ,      //         $this->getQuery() ->select( 'b.id AS brand_id,b.name AS brand_name,c.name AS country_name,b.logo,m.id AS id,m.name,' .'m.color,m.airbag,m.sales,m.speed,m.price,m.dateView') ->leftJoin('m.brand','b') ->leftJoin('b.country','c') ; //    if( !$this->get('request')->query->has('sort') ) { $this->getQuery()->orderBy('m.id','DESC'); } //   $this->buildFilterFields(); //   $this->checkFilters(); //  KnpPaginator $pagination = $this->getPaginator(30); //       $filter_form = $this->getViewFiltersForm(); //    -  $this->initAutosum(); $autosum = $this->getSumColumns(); return $this->render('AppBundle:Model:list.html.twig', array( 'results' => $pagination, 'items' => $items, 'filter_form' => $filter_form, //        'is_new' => false, //$this->isZk2Granded(array('ROLE_NEW_ITEM')), 'autosum' => $autosum, //     (PHP::number_format),      'zkNumberFormat' => array('0','.',' '), )); }   /** *    */ public function buildListFields() { $this ->addInList(array( 'name', //   $this->trans('Brand','messages'), //   'b', //   array( //      ,    ( b.name AS brand_name ) //      ,      // (    Model::getBrandName() ) 'method' => 'brand_name', //     ( @Route("/brand/{id}/edit", name="brand_edit") ) 'link_id' => 'brand_edit', //      ,    ( b.id AS brand_id ) //      ,      // (    Model::getBrandId() ) //  link_id ,  lid ,     ID    'lid' => 'brand_id' ), )) ->addInList(array( 'name', $this->trans('Country','messages'), 'c', array( 'method' => 'country_name', ), )) ->addInList(array( 'logo', $this->trans('Logo','messages'), 'b', array( 'sort' => false, 'style' => 'text-align:center', 'icon_path' => '/img/' ), )) ->addInList(array( 'name', $this->trans('Model','messages'), 'm', array( 'link_id' => 'model_edit', ), )) ->addInList(array( 'color', $this->trans('Color','messages'), 'm', array( 'style' => 'text-align:center' ), )) ->addInList(array( 'airbag', $this->trans('Airbag','messages'), 'm', array( 'filter' => 'yes_no', //   ""  "" 'style' => 'text-align:center' ), )) ->addInList(array( 'sales', $this->trans('Sales','messages'), 'm', array( 'autosum' => 'sales_sum', //     'style' => 'text-align:center' ), )) ->addInList(array( 'speed', $this->trans('Max speed','messages'), 'm', array( 'style' => 'text-align:center' ), )) ->addInList(array( 'price', $this->trans('Price','messages'), 'm', array( 'style' => 'text-align:center', 'zkNumberFormat' => array(2,'.',' ') ), )) ->addInList(array( 'dateView', $this->trans('Date','messages'), 'm', array( 'func' => 'dateTimeFormat', //  DateTime 'dateTimeFormat' => 'Ym-d', 'style' => 'text-align:center' ), )) ; }   /** *   */ public function buildFilterFields() { $this ->addInFilter(array( // --  ,   'b_name', 'zk2_admin_panel_entity_filter', $this->trans('Brand','messages'), 5, 'smal_int', array( 'entity_type' => 'entity', 'entity_class' => 'AppBundle\Entity\Brand', 'property' => 'name', 'sf_query_builder' => array( //      'alias' => 'b', 'where' => 'b.id IS NOT NULL', 'order_field' => 'b.name', 'order_type' => 'ASC', ) ))) ->addInFilter(array( 'm_name', 'zk2_admin_panel_text_filter', $this->trans('Model','messages'), 5, 'light_text' )) ->addInFilter(array( //  ,  - 'm_color', 'zk2_admin_panel_choice_filter', $this->trans('Color','messages'), 5, 'smal_int', array('sf_choice' => array( 'black' => 'black', 'blue' => 'blue', 'brown' => 'brown', 'green' => 'green', 'red' => 'red', 'silver' => 'silver', 'white' => 'white', 'yellow' => 'yellow', )), )) ->addInFilter(array( 'm_airbag', 'zk2_admin_panel_boolean_filter', $this->trans('Airbag','messages'), )) ->addInFilter(array( 'm_door', 'zk2_admin_panel_text_filter', $this->trans('Number of doors','messages'), 5, 'medium_int' )) ->addInFilter(array( 'm_speed', 'zk2_admin_panel_text_filter', $this->trans('Max speed','messages'), 5, 'medium_int' )) ->addInFilter(array( 'm_prise', 'zk2_admin_panel_text_filter', $this->trans('Price','messages'), 5, 'medium_int' )) ->addInFilter(array( //    'm_dateView', 'zk2_admin_panel_date_filter', $this->trans('Date','messages'), 2 )) ; }   /** * edit Brand Action * * @Route("/brand/{id}/edit", name="brand_edit") * * @param Request $request * @param integer $id * * @return renderView */ public function editBrandAction( Request $request, $id ) { ............ } /** * edit Action * * @Route("/model/{id}/edit", name="model_edit") * * @param Request $request * @param integer $id * * @return renderView */ public function editAction( Request $request, $id ) { ..... } }  # AppBundle:Model:list.html.twig {% extends "Zk2AdminPanelBundle::base.html.twig" %} {% block zk2_title %}Models list{% endblock %} {% block zk2_h %}<h1>General list</h1>{% endblock %} {% block zk2_body %} {% if filter_form %} {% include 'Zk2AdminPanelBundle:AdminPanel:adminFilter.html.twig' with { 'filter_form': filter_form, 'colspan': 2, {# -     #} 'this_path': path('model_list') } %} {% endif %} {% include 'Zk2AdminPanelBundle:AdminPanel:adminList.html.twig' with { 'items': items, 'results': results, 'Zk2NumberFormat': zkNumberFormat } %} {% if is_new %}  "" {% endif %} {% endblock %} Source: https://habr.com/ru/post/250039/
All Articles