Skip to content

Use custom database table fields

Benjamin Kaiser edited this page Apr 15, 2021 · 9 revisions

If you want to use a custom database table or fields, you can define them via the constructor of the f3_tree class:

F3_Tree(resource &$link , [ string $table_name = 'f3tree'] , [ string $id_column = 'id'] , [ string $title_column = 'title'] , [ string $left_column = 'lft_id'] , [ string $right_column = 'rgt_id'] , [ string $parent_column = 'parent_id']

So if you want to change the table name, simple pass it to the class constructor as the second parameter:

$f3t = new F3_Tree($f3->get('DB'), 'custom_table_name');

You can also do this for all fields in the database table. So for example if you want to use the following table as a base to store the tree structure:

category
id
name
lft
rgt
parent

You can do this by passing the following parameters to the class constructor:

$f3t = new F3_Tree($f3->get('DB'), 'category', 'id', 'name', 'lft', 'rgt', 'parent');

Clone this wiki locally