Skip to content

Instantly share code, notes, and snippets.

@des1roer
Last active August 29, 2015 14:26
Show Gist options
  • Save des1roer/c5ec8c7a9534b5760479 to your computer and use it in GitHub Desktop.
Save des1roer/c5ec8c7a9534b5760479 to your computer and use it in GitHub Desktop.
D:\open\OpenServer\domains\yii2-start\frontend\modules\main\views\mytree\index.php
<?php
///D:\open\OpenServer\domains\yii2-start\frontend\modules\main\views\mytree\index.php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel app\modules\main\models\MytreeSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Mytrees';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="mytree-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a('Create Mytree', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'root',
'lft',
'rgt',
'lvl',
// 'name',
// 'icon',
// 'icon_type',
// 'active',
// 'selected',
// 'disabled',
// 'readonly',
// 'visible',
// 'collapsed',
// 'movable_u',
// 'movable_d',
// 'movable_l',
// 'movable_r',
// 'removable',
// 'removable_all',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>
<?php
use creocoder\nestedsets\NestedSetsBehavior;
use arogachev\tree\widgets\NestedSets;
use app\modules\main\models\Mytree;
echo NestedSets::widget([
'modelClass' => Mytree::className(),
])
/*use kartik\tree\TreeView;
use app\modules\main\models\Mytree;
echo TreeView::widget([
// single query fetch to render the tree
'query' => Mytree::find()->addOrderBy('root, lft'),
'headingOptions' => ['label' => 'Categories'],
// 'fontAwesome' => true,
'isAdmin' => true, // optional (toggle to enable admin mode)
'displayValue' => 1, // initial display value
'softDelete' => true, // normally not needed to change
'cacheSettings' => ['enableCache' => true], // normally not needed to change
]);*/
/*echo TreeView::widget([
'query' => Mytree::find()->addOrderBy('root, lft'),
'headingOptions' => ['label' => 'Categories'],
'rootOptions' => ['label'=>'<span class="text-primary">Root</span>'],
'fontAwesome' => true,
'isAdmin' => true,
'displayValue' => 1,
'iconEditSettings'=> [
// 'show' => list,
'listData' => [
'folder' => 'Folder',
'file' => 'File',
'mobile' => 'Phone',
'bell' => 'Bell',
]
],
'softDelete' => true,
'cacheSettings' => ['enableCache' => true]
]);*/
////////D:\open\OpenServer\domains\yii2-start\frontend\modules\main\models\Mytree.php
<?php
use creocoder\nestedsets\NestedSetsBehavior;
use arogachev\tree\behaviors\NestedSetsManagementBehavior;
namespace app\modules\main\models;
use Yii;
/**
* This is the model class for table "tbl_tree".
*
* @property integer $id
* @property integer $root
* @property integer $lft
* @property integer $rgt
* @property integer $lvl
* @property string $name
* @property string $icon
* @property integer $icon_type
* @property integer $active
* @property integer $selected
* @property integer $disabled
* @property integer $readonly
* @property integer $visible
* @property integer $collapsed
* @property integer $movable_u
* @property integer $movable_d
* @property integer $movable_l
* @property integer $movable_r
* @property integer $removable
* @property integer $removable_all
*/
class Mytree extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'tbl_tree';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['root', 'lft', 'rgt', 'lvl', 'icon_type', 'active', 'selected', 'disabled', 'readonly', 'visible', 'collapsed', 'movable_u', 'movable_d', 'movable_l', 'movable_r', 'removable', 'removable_all'], 'integer'],
[['lft', 'rgt', 'lvl', 'name'], 'required'],
[['name'], 'string', 'max' => 60],
[['icon'], 'string', 'max' => 255]
];
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
NestedSetsBehavior::className(),
NestedSetsManagementBehavior::className(),
];
}
public function attributeLabels()
{
return [
'id' => 'Unique tree node identifier',
'root' => 'Tree root identifier',
'lft' => 'Nested set left property',
'rgt' => 'Nested set right property',
'lvl' => 'Nested set level / depth',
'name' => 'The tree node name / label',
'icon' => 'The icon to use for the node',
'icon_type' => 'Icon Type: 1 = CSS Class, 2 = Raw Markup',
'active' => 'Whether the node is active (will be set to false on deletion)',
'selected' => 'Whether the node is selected/checked by default',
'disabled' => 'Whether the node is enabled',
'readonly' => 'Whether the node is read only (unlike disabled - will allow toolbar actions)',
'visible' => 'Whether the node is visible',
'collapsed' => 'Whether the node is collapsed by default',
'movable_u' => 'Whether the node is movable one position up',
'movable_d' => 'Whether the node is movable one position down',
'movable_l' => 'Whether the node is movable to the left (from sibling to parent)',
'movable_r' => 'Whether the node is movable to the right (from sibling to child)',
'removable' => 'Whether the node is removable (any children below will be moved as siblings before deletion)',
'removable_all' => 'Whether the node is removable along with descendants',
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment