0

Hi guys, can you please suggest me a good class that supports sub-sub-sub categories. I tried a lot of them, none of them seems to fit me! I also tried to modify them for my needs, but the more i try, the worse it gets lol :P

If you know a good class, that Can add/remove/update categories with unlimited level, please suggest!

Thank you!

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by kireol
0

just brainstorming here, but can't you just create a class and have an "add subclass()" method that does a new subclass() and sets a class variable to point to it? then anytime you want to create a new level just call that class?

0

The problem is to create kinda chain, so when they get displayed!

-First Cat
---Child 1
---Child 2
-----SubChild 1
---Child 3
-----SubChild 3
-----SubChild 4
---Child 4

I hope you understand

0

like this dude

litter.php

<?php
require_once ('cat.php');

    $mommacat = new cat('First Cat');
    $mommacat->addChild('Child 1');
    $mommacat->addChild('Child 2');
    $mommacat->children[1]->addChild('SubChild 1');
    $mommacat->addChild('Child 3');
    $mommacat->children[2]->addChild('SubChild 3');
    $mommacat->children[2]->addChild('SubChild 4');
    $mommacat->addChild('Child 4');
print_r($mommacat); echo "\n\n\n";
?>

cat.php

<?php
class cat
{
    public $name;
    public $children = array();

    public function addChild($name)
    {
        $this->children[] = new cat($name);
    }

    function __construct($name)
    {
        $this->name = $name;
    }
}
?>

I mean it's not very pretty, but does what ya wanted i think

Edited by kireol: fixed code tag

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.