Answer the question
In order to leave comments, you need to log in
Why doesn't Nested Set work in Yii2?
The table has columns for the Nested Set
. As logic, the ready-made module
https://github.com/creocoder/yii2-nested-sets
is
used to build a tree and drag and drop is used
https://github.com/wbraganca/yii2-fancytree -widget
The data for it forms
https://github.com/wokster/yii2-nested-sets-tree-b...
Everything is connected, everything moves, but in the base the lft rgt and depth values are not updated correctly for the depth value even with a minus get
the code:
<?= \wbraganca\fancytree\FancytreeWidget::widget([
'options' =>[
'source' => $data,
'extensions' => ['dnd'],
'dnd' => [
'preventVoidMoves' => true,
'preventRecursiveMoves' => true,
'autoExpandMS' => 400,
'dragStart' => new JsExpression('function(node, data) {
return true;
}'),
'dragEnter' => new JsExpression('function(node, data) {
return true;
}'),
'dragDrop' => new JsExpression('function(node, data) {
$.get("move",{item: data.otherNode.data["id"], action: data.hitMode, second: node.data["id"]},function(e ) {
data.otherNode.moveTo(node, data.hitMode);
console.log(e);
});
}'),
],
]
]);
?>
public function actionMove($item,$action,$second)
{
$item_model = $this->findModel($item);
$second_model = $this->findModel($second);
switch($action) {
case 'after':
$item_model->insertAfter($second_model);
break;
case 'before':
$item_model->insertBefore($second_model);
break;
case 'over':
$item_model->appendTo($second_model);
break;
}
if($item_model->save()) {
return print_r($item_model);
}
return true;
}
Answer the question
In order to leave comments, you need to log in
Maxim Timofeev , Hello Maxim, maybe you can help. Made according to your webinar
Probably validation, make lft rgt and depth safe attributes
return [
....
[['lft','rgt','depth'],'safe'],
....
];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question