简体   繁体   中英

Creating a new page in Sonata administration page on Symfony 4

I have an existing Symfony 4 application that I want to modify. I want to add a new page and include a link to it in the left side bar https://image.ibb.co/dZnjbV/Capture.jpg

my sonata_admin.yaml looks like this

sonata_admin:
  title:                'GPAC'
  title_logo:           img/logo.png
  templates:
    layout:       "base.html.twig"
    dashboard:    "Core/dashboard.html.twig"
    list_block:   "Block/block_admin_list.html.twig"
    edit:         "CRUD/edit.html.twig"
    list:         "CRUD/list.html.twig"
  options:
    title_mode: 'single_text'
  security:
    handler: sonata.admin.security.handler.role
    role_admin: ROLE_ADMIN
    role_super_admin: ROLE_SUPER_ADMIN
  dashboard:  
    blocks:
      -
        position: left
        type: sonata.block.service.template
        settings:
          template: "Block/block_alert.html.twig"
      -
        position: right
        type: sonata.block.service.template
        settings:
          template: "Block/block_activity.html.twig"
    groups:
      admin:
        label: 'Administration'
        icon: '<i class="fa fa-database"></i>'
      skill:
        label: 'Matrice de compétences'
        icon: '<i class="fa fa-tasks"></i>'
      rc:
        label: 'Gestion des ressources'
        icon: '<i class="fa fa-user-circle-o"></i>'
      frc:
        label: 'Suivi de compétence des ressources'
        icon: '<i class="fa fa-search"></i>'
      client:
        label: 'Client (OEC)'
        icon: '<i class="fa fa-building-o"></i>'
      project:
        label: 'Gestion d''acréditation'
        icon: '<i class="fa fa-folder-open-o"></i>'
      council:
        label: 'Comités & Réunions'
        icon: '<i class="fa fa-calendar"></i>'


  assets:
    extra_stylesheets:
      - bundles/sonataadmin/vendor/admin-lte/dist/css/skins/_all-skins.min.css
    remove_stylesheets:
      - bundles/sonatacore/vendor/components-font-awesome/css/font-awesome.min.css

sonata_block:
#   default_contexts: [cms]
  blocks:
    sonata.admin.block.admin_list:
      contexts: [admin]
    sonata.admin.block.search_result:
      contexts: [admin]
    sonata.block.service.text:
      contexts: [admin]
    sonata.block.service.template:
      contexts: [admin]

My src folder is lik this https://image.ibb.co/eBFHVq/Capture2.jpg

Any help would be appreciated

To add custom admin page: you can do that very similar as Symfony:

  1. Create a Sonata Admin class that extends AbstractAdmin
  2. you have to define base route pattern and route name in there
  3. add your Actions to that controller and your template generation (render)
  4. define and create entities and methods that will return to your template(s)
  5. Register them in your services.yml with arguments and tags
  6. and you need to add this new block to config.yml (sonata_block)
  7. and of course create your twig templates too (extends sonata's standard_layout twig)

Complete example found here by kunicmarko20

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM