S
S
shanik2018-01-12 16:08:09
MySQL
shanik, 2018-01-12 16:08:09

Why doesn't Nested Set work in Yii2?

The table has columns for the Nested Set
5a58aa9b503db850450031.png
. 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;
    
    }

when moving, ajax is triggered and the data is correct
5a58aff549d86609393838.png
. Visually, everything works and the data arrives correctly on the creocoder functions, but the changes are not correct. What to do? Is it just me or do others have problems too?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shanik, 2018-01-13
@shanik

Maxim Timofeev , Hello Maxim, maybe you can help. Made according to your webinar

M
Maxim Timofeev, 2018-01-13
@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 question

Ask a Question

731 491 924 answers to any question