There is a table that contains data about a set of folders. Each folder can be a child of another. If folder_id
is null
, then it's a root level folder.
If folder_id
is a number, it is a child of the folder with that number.
id | name | folder_id |
---|---|---|
1 | images | null |
2 | css | null |
3 | home | 1 |
4 | about | 1 |
5 | includes | 2 |
Each folder is instanced as a
Folder
class, with its children on thefolders
relation:
$folder = new RootFolder(); // The root folder (id 'null').
$folder->folders // All folders that are children of root, i.e. WHERE folder_id = null
I need to generate an array of all possible folder paths, so for the table above, something like:
[
'/', // Root folder (id: null)
'/images', // id: 1
'/images/home', // id: 3
'/images/about', // id: 4
'/css', // id: 2
'/css/includes', // id: 5
];
How?!!