Answer the question
In order to leave comments, you need to log in
How to draw a Nested sets tree with all entries?
DD.
I use https://github.com/creocoder/yii2-nested-sets
If through recursion it turns out to be easy to draw by requesting descendants one after another with the "depth = 1" constraint, but a lot of requests come out.
I would like to get all the records with one request and somehow draw them, I usually saw that they use parent_id, but there is no such thing here.
Or is it possible to somehow make connections so that he builds connections with 2-3 requests? Now under 30-40 requests to render everything.
Or maybe refuse it, but then what is better? Need to make a list of sections of 3-4 levels with 50-60 items
Answer the question
In order to leave comments, you need to log in
$myModel = MyModel::find()->orderBy('lft')->all();
Further recursion in php. 1 request. The trick is sorting by lft. Then you already have the correct ordered structure, it only remains for it to nest based on depth.
Alternatively, you can look here:
https://github.com/yiiext/nested-set-behavior/blob...
there is a php example at the bottom. It is for yii1, but in fact everything is the same
like nothing unusual, make a request and select all records, then make a recursive function in php and build a tree, here instead of parent_id, as far as I understand, the indication lft is used - the element on the left is apparently the parent, and rgt is the child element. The function is searched by the search engine in a minute, at the request of the recursion tree nested sets.
Good morning.
In ActiveRecord, you can make links from one model to another. If you are talking about this, then look here (Working with connected data).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question