You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+111-5Lines changed: 111 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,14 @@
1
1
# CI3-Navigation-Library
2
2
Simple library for CodeIgniter v3 which outputs nav links in <ul> with support for active pages and multiple menus.
3
3
4
-
Author: **Daniel Waghorn**
4
+
The library makes use of an underlying database for storing menus and the items within these menus. This provides a solid and familiar foundation on which front end management tools can be built on to allow users to manage the menus.
This project is released in the public domain under the [MIT Licence](http://opensource.org/licenses/MIT).
11
+
7
12
## Structure
8
13
The folders in this repo are as follows:
9
14
@@ -18,9 +23,110 @@ The folders in this repo are as follows:
18
23
## Usage
19
24
### Setup
20
25
1. Setup the database schema by importing the SQL file for navigation to create tables.
21
-
2. Copy the contents of `libraries` and `models` into their respective folders in your `application` directory.
22
-
3. Import the library whenever you need to output navigation; typically your header partial view using:
26
+
2. Copy the contents of `config`, `libraries` and `models` into their respective folders in your `application` directory.
27
+
3. Import the library whenever you need to output navigation and invoke generation by following the steps below at [Using the Library](#using-the-library)
28
+
29
+
30
+
### Database Structure
31
+
The tables used by the database should be in your primary CodeIgniter database and consist of `ci-nav-menus`, `ci-nav-items` and `ci-nav-inmenu`.
32
+
33
+
The `ci-nav-menus` table links `MenuID`s to a human readable `MenuName`. For example if I needed a user menu and an admin menu in my application this table would consist of two rows e.g:
34
+
35
+
| MenuID | MenuName |
36
+
| ------ | ------------------- |
37
+
| 1 | users |
38
+
| 2 | admin |
39
+
40
+
41
+
A table named `ci-nav-items` holds individual navigation items or links and their related data. This promotes reuse of items across multiple menus.
42
+
43
+
*`ItemID` is the primary key which is used to link items into menus.
44
+
*`ItemName` is merely a name which makes the item easily recognisable in the database tables.
45
+
*`ItemHumanName` is the name which is rendered in the output for the item. This can include HTML if you want to include e.g. an icon font for each item.
46
+
*`ItemLink` is the URL that links to the item's destination. This should be relative if linking internally; for instance if your login url is `http://mysite.com/login` the value in this field would simply be `login`. If linking externally then include a fully qualified url such as `http://externalsite.com/page`.
47
+
*`ParentItem` links nav items to another nav item which would be its parent. If a nav item has other nav items referring to its `ItemID` in their respective `ParentItem` field then a submenu will be rendered underneath this item.
48
+
** N.B. This field should be [NULL] by default.
49
+
50
+
Finally a table named `ci-nav-inmenu` links nav items to menus. This table contains three columns:
51
+
*`MenuID` which references the `MenuID` for a given menu in `ci-nav-menus`.
52
+
*`ItemID` which references the `ItemID` for the item to link into the menu as in `ci-nav-items`
53
+
*`LinkWeight` which assigns a weight to a particular relation. Larger `LinkWeight`s sink to the bottom/end of menu, lower `LinkWeight`s float to the top/start of menu.
54
+
55
+
For example to place a nav item with `ItemID` = 2 into the menu with `MenuID` = 1 the `ci-nav-inmenu` table should contain the following row:
56
+
57
+
| MenuID | ItemID | LinkWeight |
58
+
| ------ | ------ | ---------- |
59
+
| 1 | 2 | 50 |
60
+
61
+
I assigned `LinkWeight` 50 since on a scale of 1 to 100 this would be neutral, and leaves plenty of options to arrange links either side.
62
+
63
+
### Navigation Configurations
64
+
This library supports interchangeable config files which control the markup used when rendering the navigation. These files reside in the `config` folder, where the default config file which is loaded is `navigation.php`.
65
+
66
+
This file contains PHPdoc explaining each of the settings and what they control.
67
+
68
+
To specify an alternative configuration to load simply supply an associative array as a second parameter when loading the library as below.
The associative array should contain `'config' => 'config_file_name'`. ** Make sure not to include the .php extension when specifying `config_file_name`.
75
+
76
+
### Using the Library
77
+
Using the library is simple; in each controller it's easiest to load it in the constructor for that controller like so:
78
+
79
+
```php
80
+
$this->load->library('navigation');
81
+
```
82
+
83
+
You can also alternatively autoload it or implement it in your `MY_Controller` superclass constructor.
84
+
85
+
Whenever you need to output navigation it's normally easiest to have CodeIgniter return the markup rather than render it. This way you can pass the markup to your views via `$data` and output it exactly where you need it.
This would generate the markup for the menu with ID 2.
120
+
121
+
#### Generate Role Based Nav
122
+
This function allows you to generate a menu based on a user's group association if your project is using [Ben Edmund's Ion Auth](http://benedmunds.com/ion_auth/"Ion Auth Homepage") library.
123
+
Define user groups in Ion Auth, then edit `generateRoleBasedNav` to return the menu specific to the context.
124
+
125
+
The default method contains a few examples for integration as well as support for public, user and admin menus out of the box.
0 commit comments