Thinkphp5路由及其用法

访问地址:/index.php/index/a/index

注释:(index.php默认入口文件)    (index是控制器的文件夹下)(a是控制器名称) (index是方法)

在application(应用目录下)下的index/controller创建控制器

composer创建控制器命令:

php think make:controller name

    注:控制器开头必须大写第一个字母,否则会报错

视图:创建在controller平级(view) 

模型:创建在controller评级 model

composer创建模型命令:

php think make:model name

引入模型如下:

返回视图:return view('show')->直接进入想要的视图,'show'上级有文件夹也没关系,但是必须要跟类型相同才可以,因为是直接找跟类名相同的文件夹

重定向:

跟laravel格式一样:return redirect("/index.php/api/index/file");

 跳转路由方法如下:

<a href="/index.php/api/index/file"></a>



form表单跳转如下:
action="{:url('index/add')}";//index是控制器,add是方法

其二根据<a>标签方式跳转也是可以的
                                              CURD
thinkphp5其实跟laravel的curd基本一致

引用DB文件后可以用

增加:$sql=Db:table('student')->insert($data);

删除:  $sql=Db:table(''student)->where('id',1)->delete();

修改:  $sql=Db:table(''student)->where('id',1)->update();

查询:  $sql=Db:table('student')->select();

  

猜你喜欢

转载自blog.csdn.net/qq_43572631/article/details/85068348