<?php use yii\helpers\Html; use yii\helpers\ArrayHelper; use yii\bootstrap\ActiveForm; use app\models\Nav; /** * @var yii\web\View $this * @var app\models\Nav $model * @var yii\widgets\ActiveForm $form */ $category = new Nav(); $Categories = $category->roots()->all(); $level = 0; $items[0] = Yii::t('app', 'Please select the parent node'); foreach ($Categories as $key => $value) { $items[$value->attributes['id']] = $value->attributes['name']; $children = $value->descendants()->all(); foreach ($children as $child) { $string = ' '; $string .= str_repeat('│ ', $child->level - $level - 1); if ($child->isLeaf() && !$child->next()->one()) { $string .= '└'; } else { $string .= '├'; } $string .= '─' . $child->name; $items[$child->id] = $string; } } if (!$model->isNewRecord) {
<div class="nav-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <p> <?php echo Html::a(Yii::t('app', 'Create Nav'), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php $category = new Nav(); $roots = $category->roots()->all(); foreach ($roots as $key => $root) { $categories = Nav::find()->where(['root' => $root->id])->orderBy('lft')->all(); $level = 0; foreach ($categories as $n => $category) { if ($category->level == $level) { echo Html::endTag('li') . "\n"; } elseif ($category->level > $level) { echo Html::beginTag('ul') . "\n"; } else { echo Html::endTag('li') . "\n"; for ($i = $level - $category->level; $i; $i--) { echo Html::endTag('ul') . "\n"; echo Html::endTag('li') . "\n"; } }