~~~
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\Classification;
$tree = Tree::instance();
$tree->init(collection($this->model->select())->toArray(), 'pid');
$this->categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name');
$categorydata = [0 => ['type' => 'all', 'name' => __('None')]];
foreach ($this->categorylist as $k => $v) {
$categorydata[$v['id']] = $v;
}
$this->view->assign("parentList", $categorydata);
}
~~~
add
~~~
<div class="form-group">
<label for="c-pid" class="control-label col-xs-12 col-sm-2">{:__('父级')}:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-pid" data-rule="required" class="form-control selectpicker" name="row[pid]">
{foreach name="parentList" item="vo"}
<option value="{$key}" {in name="key" value=""}selected{/in}>{$vo.name}</option>
{/foreach}
</select>
</div>
</div>
~~~
edit
~~~
<div class="form-group">
<label for="c-pid" class="control-label col-xs-12 col-sm-2">{:__('父级')}:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-pid" data-rule="required" class="form-control selectpicker" name="row[pid]">
{foreach name="parentList" item="vo"}
<option class="" value="{$key}" {in name="key" value="$row.pid"}selected{/in}>{$vo.name}</option>
{/foreach}
</select>
</div>
</div>
~~~