thinkphp5-控制器

命令行生成控制器

php think make:controller index/User

渲染模板

use think\View;

$view = new View();
$view->assign('name','huyongjian');
return $view->fetch('index');

初始化方法

public function _initialize()
    {
        echo 'init<br/>';
    }

成功和错误跳转

$this->success('新增成功', 'create');
$this->error('新增失败');

空操作

public function _empty($name)
{
    echo 'empty:'.$name;
}

空控制器

<?php
namespace app\index\controller;

use think\Request;

class Error
{
    public function index(Request $request)
    {
        echo 'error controller: '.$request->controller();
    }

}
posted @ 2021-10-30 14:49  胡勇健  阅读(30)  评论(0)    收藏  举报