Giter Site home page Giter Site logo

bonfire-categories's Introduction

bonfire-categories

Menus and categories module for Codeigniter Bonfire. This module uses drag-and-drop approach to manage menus and menu items, similar to the one used in the Wordpress CMS menus.
Please see the screenshot:

Installation instructions

  1. Download zip archive with the source code.
  2. Upload 'categories' folder to the: application/modules folder on your server.
  3. Navigate to: Developer -> Database tools -> Migrations, click on Modules tab and migrate Categories module to the highest version.

The back-end to the Menus and Categories module is located at: yoursite.com/admin/content/categories. Sample public-facing page / Front-end can be found at: yoursite.com/categories, you may want to look at the index.php in the module's 'views' folder to see how to work with menus and categories in your front-end pages.

Displaying Navigation in Your Pages

The Categories module comes with the helper file which can be used in your controller or view file. The code to load the helper is:

$this->load->helper('categories/categories');

The following functions are available:

list_all_menus() - get the list of menus as an array of objects or empty array if no menu's found

list_menu_categories($id) - *get full navigation for a given menu 'id' ($id is required) - the id parameter for the menu. The function will return an array of category objects (in case navigation have nested categories the function will return the tree object)

find_a_category($id, $name) - find a category by it's 'id' or 'name' field (at least one of parameters is required) The function will return a category object if the id or name param matches an existing category, otherwise return false.

Below is the code snipplet that shows how you can easily handle nested menus on the front-end:

function build_nested_menu($categories, $outstring="") {
	if(empty($categories)) return $outstring;
	$outstring .= '<ul> ';
	foreach($categories as $cat) {
		$outstring .= '<li><a href="'.$cat->url.'">'.$cat->name.'</a> ';
			if(isset($cat->nodes)) 
				return build_nested_menu($cat->nodes, $outstring) .'</ul> ';
		$outstring .= '</li> ';
	}
	$outstring .= '</ul> ';
	return $outstring;
} 

// Load categories helper
$this->load->helper('categories/categories');

// Loop thru all menus
foreach(list_all_menus() as $menu) {
	echo build_nested_menu(list_menu_categories($menu->id));
}

bonfire-categories's People

Contributors

andyvr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.