Core Boxx – Dynamic Menu Module

 

TABLE OF CONTENTS

Download & License Installation What Is This?
User Database User Functions User API

 

 

DOWNLOAD & LICENSE

Download Core Boxx Menu ModuleSource Forge

Core Boxx is released under the MIT License. You are free to use it for your own personal and commercial projects, modify it as you see fit. On the condition that there the software is provided “as-is”. There are no warranties provided and “no strings attached”. Code Boxx and the authors are not liable for any claims, damages, or liabilities.

 

INSTALLATION

Download and set up the “main Core Boxx” if you have not already done so. Then, create your database and import menu.sql… Remember to delete this file afterward, that’s all.

 

 

WHAT IS THIS MODULE?

This is a simple dynamic menu module for Core Boxx – If you want to dynamically create and update menus like a CMS. Simply plug this one into Core Boxx, and the foundations are done. Minus the HTML/CSS/Javascript, that is.

 

MENU DATABASE TABLES

Menu
Field Description
menu_id Menu ID, primary key.
menu_name Name of the menu. E.G. Main menu, side-bar menu, footer menu, etc…
menu_desc A short description of the menu.
Menu Items
Field Description
menu_id Menu ID, foreign and primary key.
item_id Menu item ID, primary key. Take note – This is not auto-increment. You need to manually specify this, and also use this as the menu item sort order.
parent_id For nested menu items – The parent item ID. Leave as NULL if root level.
item_label The label of the menu item.
item_link Where the menu item links to.
item_target Optional. This should either be _BLANK or _SELF if you want to set.

 

 

MENU LIBRARY FUNCTIONS

Function Description & Quick Example
save($name, $desc, $id) Add a new menu, or update an existing menu.

  • $name String, the menu name.
  • $desc String, short menu description.
  • $id Int, pass in the menu ID if you want to update an existing menu.
echo $_CORE->Menu->save(
  "Main Menu", "Top navigation bar"
) ? "OK" : $_CORE->error ;
saveItems($id, $items) Save/update menu items.

  • $id Int, the menu ID.
  • $items Array, the menu items.
echo $_CORE->Menu->saveItems(1, [
  // ITEM ID, PARENT ID, LABEL, LINK, TARGET
  // START WITH ROOT!
  [1, null, "Blog", "blog/", null],
  [2, null, "Products", "products/", null],
  [3, null, "Reviews", "reviews/", null],
  // SECOND LEVEL
  [4, 1, "Tech", "blog/tech/", "_SELF"],
  [5, 1, "Hacks", "blog/hacks/", "_BLANK"]
  // WE CAN GO DEEPER, BUT SHALL STOP AT 2 LEVELS
  // [6, 5, "Windows", "blog/hacks/windows", null]
  // [7, 5, "Mac", "blog/hacks/mac", null]
]) ? "OK" : $_CORE->error ;
del($id) Delete an entire menu and items.

  • $id Int, the menu ID
echo $_CORE->Menu->del(1) ? "OK" : $_CORE->error ;
get($id) Get the specified menu.

  • $id Int, the menu ID
$menu = $_CORE->Menu->get(1);
getAll() Get all menus.

$menu = $_CORE->Menu->getAll();
getItems($id) Get all items of the specified menu.

  • $id Int, the menu ID
$items = $_CORE->Menu->get(1);
toHTML($id) This is an incomplete support function for save() – Generates a static HTML file for the menu, to speed up the performance of your website. I.E. Directly load the menu HTML instead of generating from the database every time.

  • $id Int, the menu ID

 

 

MENU API FUNCTIONS

Accessible at http://yoursite.com/api/menu/REQUEST/. These are pretty much a replica of the above library functions, except in REST API format. Feel free to delete api/menu.php if you don’t intend to integrate an API.

Request Description & Parameters
save Add or update the menu.

  • $_POST['name'] – String, menu name.
  • $_POST['desc'] – String, menu description
  • $_POST['id'] – Int, optional menu ID. Pass in to update instead of add.
saveItems Save menu items.

  • $_POST['id'] – Int, menu ID.
  • $_POST['items'] – Array, menu items. The format is the same as above in the functions.
del Delete a menu.

  • $_POST['id'] – Int, menu ID.
get Get a menu.

  • $_POST['id'] Int, menu ID.
getAll Get all menus.
getItems Get all items for the specified menu.

  • $_POST['id'] Int, menu ID.

Leave a Comment

Your email address will not be published. Required fields are marked *