复习
1.路由
a.有利于SEO优化
b.简介方便记忆
2.路由模式
1.普通模式(PATHINFO)
http://www.tp.com/index.php/index/index/index
2.混合模式
支持PATHINFO和路由
3.强制模式
只支持路由模式
4.模式切换和配置文件有关
// 是否开启路由
'url_route_on' => true,
// 是否强制使用路由
'url_route_must' => false,
3.设置路由
0.配置文件
项目\application\Route.pp\hp
1.动态设置单个路由
use think\Route;
Route::rule();
Route::get();
Route::post();
Route::delete();
Route::put();
2.动态批量设置路由
Route::rule([
'路由规则1'=>'路由地址和参数',
'路由规则2'=>['路由地址和参数','匹配参数(数组)','变量规则(数组)'],
...
],'请求类型','匹配参数(数组)','变量规则');
3.配置文件注册路由
return [
"index"=>"index/index/index",
"diaoyong"=>"index/index/diaoyong",
"type/:id"=>"index/index/type"
];
今日学习
一、新建控制器(前台模块为例)
1.在前台控制器目录下(项目\application\index\controller)
新建控制器文件User.php
2.User.php文件中如何书写
<?php
// 声明命名空间
namespace app\index\controller;
// 声明控制器
class User
{
public function index