Fractal tree rendering with Agile Toolkit

I have the following situation. I have a model A with the following properties: id int name varchar (255) parent_id int (refers to the same model A).

Now I need to display the Tree View using ModelA. Of course, I could just load all the data, sort it correctly by parent_id and “render” using the traditional string binding. eg.

class Model_A extends Model_Table { ... function render_branch($nodes, $parent){ if (!isset($nodes[$parent])){ return null; } $out = "<ul>"; foreach ($nodes[$parent] as $node){ $out .= "<li>" . $node["name"]; $out .= $this->render_branch($nodes, $node["id"]); $out .= "</li>"; } return $out; } function init(){ parent::init(); $nodes = array(); // preload from db and arrange so that key = parent and content is array of childs $this->template->set("tree", $this->render_branch($nodes, 0)); } } 

now I would instead like to use my own liker / smlite atk4 template analyzer for this purpose. but, if you try to do this, then you will have an unpleasant lister, where in the format line you still try to substitute a specific tag at the output of another lister, which in fact you will have to destroy to fill the void memory.

any suggestions?

ps the code above is not tested, just shows the concept

thanks!

+6
source share
2 answers

Well, the right time has come and the right addition has been created. To use it, get your add-ons and atk4 up to date and follow this article to find out how.

http://www.ambienttech.lv/blog/2012-07-06/tree_view_in_agile_toolkit.html

+3
source

According to Jancha's comment

Well, having spent some time on the possible options, I found that the simplest in this particular case was the use of the above example. The only way to make it more native is to use an external template for nodes and use the smite and clone area + render to move the html out to the template. in addition, using a traditional lister did not seem to be effective enough. therefore, atk4 guys, stay tuned for viewing the plugin query tree and create the correct backend! It would be cool. thanks j

.

0
source

Source: https://habr.com/ru/post/896258/


All Articles