如果你使用了多級(jí)控制器的話,可以設(shè)置controller_auto_search參數(shù)開啟自動(dòng)定位控制器,便于URL訪問,例如首先在配置文件中添加:

'controller_auto_search' => true,

然后定義控制器如下:

namespace app\index\controller\one;

use think\Controller;

class Blog extends Controller
{
    public function index()
    {
        return $this->fetch();
    }
    
    public function add()
    {
        return $this->fetch();
    }
    
    public function edit($id)
    {
        return $this->fetch('edit:'.$id);
    }
}

我們就可以直接訪問下面的URL地址了:

http://serverName/index.php/index/one/Blog