Add links to custom pages in the Bootstrap Admin Navbar

To add links to custom pages in the Bootstrap Admin Panel sidebar you have to create your page, map it with the main router then add it in the sidebar.


Link to custom pages in the Bootstrap Admin Panel sidebar

  1. Create your target file in admin/
    ie: my-custom-page.php
  2. Create a new router rule in admin/index.php to lead to your new page.
    ie: $router->map('GET', '/my-custom-page', 'my-custom-page.php', 'my-custom-page');
  3. Add your page to the sidebar:
    1. open admin\inc\sidebar.php
    2. Add the following code at the end of the file & customize as desired:
      $active = false;
      
      // test if the page is active using $match from the router.
      // 'my-custom-page' is the name we gave in index.php => $router->map()
      if (isset($match['name']) && $match['name'] == 'my-custom-page') {
      $active = true;
      $is_category_collapsed = false;
      }
      
      // add category
      $sidebar->addCategory('new-category', 'New Category', '', '', true, $is_category_collapsed);
      
      // 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('my-custom-page', 'nav flex-column');
      
      // add page into nav - the 'myCustomPage' object is the sidebar's category newly created nav.
      // its name ('myCustomPage') is the lower-camelcase version of 'my-custom-page'
      $sidebar->newCategory->myCustomPage->addLink(ADMIN_URL . 'my-custom-page', 'MyCustom Page', 'fas fa-users', $active, 'class=nav-item', 'class=nav-link d-flex align-items-center');
  4. Done.

PHP CRUD tutorial main page