>Controller源码示例
```
<?php
namespace app\index\controller;
use think\Controller;
class Authrule extends Controller
{
public function index() //index()方法用于添加信息到数据库
{
if(request()->isPOST()) {
$data = input('post.');
$plevel = Model('Rule')->getPlevel($data['pid']); //不仅要得到父类id,我也要得到父类level,这样我+1就能得到我自己的level
if($plevel){ //Mode层得到的是一维数组,调用的方法是column(‘level’),得到数据筛选只要level字段信息,且只有一个信息,如果为0说明是一级,+1得到自己等级
$data['level']=$plevel['0']+1;
}else{
$data['level']=0;
}
$res = Model('Rule')->save($data);
if($res){
$this->success('Success');
}else{
$this->error('Error');
}
}else{
$res = Model('Rule')->tree();
$this->assign('res',$res);
return $this->fetch();
}
}
public function lst() //lst()方法将数据库里所有信息展示出来
{
$res = Model('Rule')->tree(); //tree()方法是自己写的函数,用于将所有数据库数据根据pid和level字段进行分组,以树状展示
$this->assign('res',$res);
return $this->fetch();
}
}
```