protected function findModel($id) { if (($model = Tree::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<?php //$roots = Tree::findOne(['id'=>'22']); //$roots->deleteWithChildren(); //$countries = new Tree(['name' => '<b>Uxaa-xa<b>']); //$countries->makeRoot(); //$roots = Tree::findOne(['id'=>'24']); //$child = new Tree(['name' => 'Вложение 3го уровня 3-4-1']); //$child->appendTo($roots); //$child = new Tree(['name' => 'Вложение 3го уровня 3-4-2']); //$child->appendTo($roots); ?> <?php $data = Tree::nparseData(NULL, NULL, TRUE); //print_r($data); ?> <div> <?php Pjax::begin(['id' => 'pjax-container']); ?> <div> <p> <?php echo Html::a('<span class="glyphicon glyphicon-tree-conifer"></span> Новый корень', ['#'], ['data-toggle' => 'modal', 'data-target' => '#m_root', 'class' => 'btn btn-info', 'title' => 'Добавляет новый корень в дерево']); ?> <?php echo Html::a('<span class="glyphicon glyphicon-asterisk"></span> Редактировать', ['#'], ['data-toggle' => 'modal', 'data-target' => '#m_edit', 'class' => $id > 0 ? 'btn btn-info' : 'btn btn-info disabled', 'title' => 'Добавляет новый корень в дерево']); ?>
public static function nparseData($ids = null, $id = NULL, $select = FALSE) { $masTree = Tree::find()->select(['id', 'root', 'lvl', 'name as text', 'id_device'])->where(!is_null($id) ? ['root' => $id] : '')->orderBy(['root' => SORT_ASC, 'lft' => SORT_ASC])->createCommand()->queryAll(); return self::nrec($ids, $masTree, null, $select); //print_r($masTree); }
timeout: null }); } var otherTreeWidgetEl = \$('.treeview.small').not(\$(this)), otherTreeWidget = otherTreeWidgetEl.data('treeview'), selectedEl = otherTreeWidgetEl.find('.node-selected'); if (selectedEl.length) { otherTreeWidget.unselectNode(Number(selectedEl.attr('data-nodeid'))); } } JS ); $items = [['text' => 'Parent 1', 'href' => Url::to(['', 'page' => 'parent1']), 'nodes' => [['text' => 'Child 1', 'href' => Url::to(['', 'page' => 'child1']), 'nodes' => [['text' => 'Grandchild 1', 'href' => Url::to(['', 'page' => 'grandchild1'])], ['text' => 'Grandchild 2', 'href' => Url::to(['', 'page' => 'grandchild2'])]]]]]]; echo TreeView::widget(['data' => $items, 'size' => TreeView::SIZE_SMALL, 'clientOptions' => ['onNodeSelected' => $onSelect]]); $users = Tree::find()->orderBy('root', 'lft')->all(); $level = 0; foreach ($users as $n => $user) { if (!$user->lvl) { echo Html::beginTag('ul') . PHP_EOL; } if ($user->lvl && $user->lvl == $level) { echo Html::endTag('li') . PHP_EOL; } elseif ($user->lvl > $level) { echo PHP_EOL . Html::beginTag('ul') . PHP_EOL; } else { if ($user->lvl) { echo Html::endTag('li' . $user->lvl) . PHP_EOL; } for ($i = $level - $user->lvl; $i; $i--) { echo Html::endTag('ul') . PHP_EOL;