Adição de páginas personalizadas à navegação administrativa do Bootstrap
Guia de personalização de menus

Para adicionar links a páginas personalizadas na barra lateral do painel de administração do Bootstrap, o senhor precisa criar sua página, mapeá-la com o roteador principal e adicioná-la à barra lateral.


A estrutura da barra lateral

A barra lateral é composta de categorias, navegações e links. As categorias são as seções principais da barra lateral, as navs são as subseções das categorias e os links são os links reais para as páginas.

Aqui está a estrutura:

Sidebar structure

Link para página(s) personalizada(s) na barra lateral do painel de administração do Bootstrap

  1. Crie seu(s) arquivo(s) de destino em admin/
    ou seja: admin/custom-page-one.php e admin/custom-page-two.php
  2. Crie novas regras de roteamento em admin/index.php para levar à(s) nova(s) página(s), por exemplo:
    // add your custom page(s) to the router
    // the first parameter is the method (GET, POST, PUT, DELETE)
    // the second parameter is the path to the page
    // the third parameter is the name given to the route (any arbitrary name. It must be unique, without spaces, without special characters)
    $router->map('GET', '/custom-page-one', 'custom-page-one.php', 'custom-page-one');
    $router->map('GET', '/custom-page-two', 'custom-page-two.php', 'custom-page-two');
  3. Adicione sua(s) página(s) à barra lateral

    O código a seguir cria uma nova categoria chamada "My New Category", depois adiciona um objeto Nav à categoria e, por fim, adiciona os links ao objeto Nav.

    Os métodos usados nesse código são os seguintes:

    • Sidebar::addCategory() - adiciona uma nova categoria à barra lateral - /class/bootstrap/sidebar/Sidebar.php
    • SidebarCategories::addNav() - adiciona um novo objeto Nav à categoria - /class/bootstrap/sidebar/SidebarCategories.php
    • Nav::addLink() - adiciona um novo link ao objeto Nav - /class/bootstrap/sidebar/Nav.php
    1. abrir admin\inc\sidebar.php
    2. Adicione o código a seguir no final do arquivo e personalize-o como desejar:
      
      // create an array with the pages that we'll add to the "My New Category" category
      // using the route names we gave in index.php => $router->map()
      $category_pages = array('custom-page-one', 'custom-page-two');
      
      /* ===================================
      =              Category              =
      ==================================== */
      
      $is_category_collapsed = true;
      
      // test if the active (current) page is in the $category_pages array using $match from the router
      // and expand the category accordingly
      if (isset($match['name']) && in_array($match['name'], $category_pages)) {
          $is_category_collapsed = false;
      }
      
      // add the category
      $sidebar->addCategory('new-category', 'New Category', '', '', true, $is_category_collapsed);
      
      /* ===================================
      =                 Nav                =
      ==================================== */
      
      // create a nav object inside the category. The nav object will contain the links
      // add nav into category - the 'newCategory' object is the sidebar's newly created category.
      // its name ('newCategory') is the lower-camelcase version of 'new-category'
      $sidebar->newCategory->addNav('new-nav', 'navbar-nav flex-column py-0');
      
      /* ===================================
      =                Links               =
      ==================================== */
      
      // first link
      
      $active = false;
      
      // check if the page is active and set the active variable to true
      if (isset($match['name']) && $match['name'] == 'custom-page-one') {
          $active = true;
      }
      
      // add the first link to the nav object
      $sidebar->newCategory->newNav->addLink(ADMIN_URL . 'custom-page-one', 'Custom page one', 'fas fa-circle-info', $active, 'class=nav-item', 'class=nav-link d-flex align-items-center');
      
      // second link
      
      $active = false;
      
      // check if the page is active and set the active variable to true
      if (isset($match['name']) && $match['name'] == 'custom-page-two') {
          $active = true;
      }
      
      // add the second link to the nav object
      $sidebar->newCategory->newNav->addLink(ADMIN_URL . 'custom-page-two', 'Custom page two', 'fas fa-users', $active, 'class=nav-item', 'class=nav-link d-flex align-items-center');
      
  4. Feito.

Página principal do tutorial PHP CRUD