@Sandro_s

Nested sets с drag&drop почему не выпадает список?

Должно быть так по идее:
5a5ba1308d946369166590.jpeg
но у меня вот так:
5a5ba14e1c04c596043603.jpeg5a5ba159250ee956518036.jpeg

Кнопка 'create', если нажать + открывает страницу 'создать меню'. Больше ничего не работает.

MenuController
spoiler
<?php

namespace backend\controllers;

use Yii;
use common\models\Menu;
use common\models\MenuSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

/**
* MenuController implements the CRUD actions for Menu model.
*/
class MenuController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}

/**
* Lists all Menu models.
* return mixed
*/
public function actionIndex()
{
$searchModel = new MenuSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);

return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}

/**
* Displays a single Menu model.
* @param integer $id
* return mixed
*/
public function actionTree($id = 1)
{
return $this-> render ('tree', [
'data' => Menu::findOne($id)->tree()
]);
}

public function actionMove ($item,$action,$second)

{
$item_model = Menu::findOne($item);
$second_model = Menu::findOne($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;
}
$item_model->save();
return true;
}
/**
* Creates a new Menu model.
* If creation is successful, the browser will be redirected to the 'view' page.
* return mixed
*/

public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}


public function actionViewAjax($id)
{
return $this->renderAjax('_form',[
'model'=> $this->findModel($id),
]);
}

public function actionCreate()
{
$model = new Menu ();
if ($model->load(Yii::$app->request->post())) {

if ($model->sub == null) {
$model->makeRoot();
}else{

$parent = Menu::find()->andWhere(['id'=>$model->sub])->one();
$model->prependTo($parent);
}
if ($model->save()){
return $this->redirect(['tree', 'id' => $model->id]);

}
}

return $this->render('create', [
'model' => $model,
]);

}

/**
* Updates an existing Menu model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);

if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['tree', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}

/**
* Deletes an existing Menu model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();

return $this->redirect(['index']);
}

/**
* Finds the Menu model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* return Menu the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Menu::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}


Menu
spoiler
<?php

namespace common\models;

use Yii;
use creocoder\nestedsets\NestedSetsBehavior;
use wokster\treebehavior\NestedSetsTreeBehavior;

/**
* This is the model class for table "menu".
*
* @property integer $id
* @property integer $tree
* @property integer $lft
* @property integer $rgt
* @property integer $depth
* @property string $name
* @property string $url
* @property string $text
*/
class Menu extends \yii\db\ActiveRecord
{
public $sub;
/**
* @inheritdoc
*/
public static function tableName()
{
return 'menu';
}

public function behaviors() {
return [
'tree' => [
'class' => \creocoder\nestedsets\NestedSetsBehavior::className(),

],
'htmlTree'=>[
'class'=> \wokster\treebehavior\NestedSetsTreeBehavior::className()
]
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[[ 'name', 'url'], 'required'],
[['tree', 'lft', 'rgt', 'depth','sub'], 'integer'],
[['name'], 'string', 'max' => 255],
[['url'], 'string', 'max' => 50],
[['text'], 'string', 'max' => 1000],
[['lft','rgt','depth','tree',],'safe']
];
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'tree' => 'Tree',
'lft' => 'Lft',
'rgt' => 'Rgt',
'depth' => 'Depth',
'name' => 'Name',
'url' => 'Url',
'text' => 'Text',
];
}

public function transactions()
{
return [
self::SCENARIO_DEFAULT => self::OP_ALL,
];
}

public static function find()
{
return new MenuQuery(get_called_class());
}

}



tree.php
spoiler

<?php
use yii\web\JsExpression;
use wbraganca\fancytree\FancytreeWidget;

/**

/* var $this yii\web\View */
/* var $data array */

$this->title = 'дерево категорий';
?>




дерево




<? \wbraganca\fancytree\FancytreeWidget::widget([
'options' => [
'source' => $data,
'extentions' => ['dnd'],
'dnd' => [
'preventVoidMovis'=> 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("/menu/move",(item: data.otherNode.key.substr(1), action: data.hitMode, second:node.key.substr(1)},function() {
data.otherNode.moveTo(node, data.hitMode);
});

}'),

],

'activate' => new JsExpression ('function(event,data) {
var title = data.node.title;
var id = data.node.key.substr(1);
$("#cat-info .box-header>h3") .text(title);
$.get("/menu/view-ajax",(id: id),function(data) {
$("#cat-info" .box-body").html (data);
});
}'),
]
]);
?>







инфо






class="box-body">


  • Вопрос задан
  • 89 просмотров
Пригласить эксперта
Ответы на вопрос 1
webinar
@webinar Куратор тега Yii
Учим yii: https://youtu.be/-WRMlGHLgRg
<? \wbraganca\fancytree\FancytreeWidget::widget([
видимо надо заменить на
<?= \wbraganca\fancytree\FancytreeWidget::widget([
Вы же ничего не вывели, с чего бы там чему-то взяться?
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы