We have decided to release one of our own major libraries (well model in this case) to all of the great CodeIgniter coders out there so we can give back to the community here and help some others save a heap of time.
We needed a class that would retrieve a block of data with parent/child relationships from mySQL and store it in an array which correctly represents the three dimensional nature of the parent/child relationships. The class needed to also have methods for add, deleting and moving entries within and between categories.
This model is perfect for the management of a menu for a website that has multiple or single levels of navigation.
What is the model for?
Essentially we want to turn this:
PK parent name
-------------------------
1 0 Animals
2 1 Cat
Into this:
Array
(
[0] => Array
(
[PK] => 1
[parent] => 0
[name] => Animals
[childs] => Array
(
[0] => Array
(
[PK] => 2
[parent] => 1
[name] => Cat
)
)
)
And also be able to manage the data set easily as well.
What can it do ?
The model contains simple functions to manage the data items such as:
$this->HModel->add_item("test item", 3);
$this->HModel->delete_item(53);
$this->HModel->move_item_down(14);
$this->HModel->is_item_live(21);
How do I get it?
Checkout our blog post for more information or below are some quick links to the code and documentation:
I need some help!
Then feel free to reply in here or to our original blog post. Myself or David (pawz) will be more then help out or even take any suggestions on how to improve this model.