基础访问流程
URL访问规则
控制器文件创建规则 开头首字母大写,双字母的时候两个大写浏览器访问中间加“下划线“或者在app.php文件配置。
ThinkPHP5.1配置获取与设置
获取:Config::get()
设置:Config::set()
查询:Config::has()
助手函数 config()
前置操作
继承Controller类后可以设置一个$beforeActionList属性来创建前置方法;
<?php
namespace app\admin\controller;
use think\Controller;
class Befor extends Controller {
// 数组里面写想要执行的方法名称。
protected $beforeActionList=[
'frist',
#是指first前置规则中except指向one方法,也就是调用one方法时second不会调用
'second' => ['except'=>'one'],
#是指second前置规则中only指向three方法,也就是thrid只能three调用
'thrid' => ['only'=>'three']
];
protected function frist (){
echo "frist".'<br/>';
}
protected function second(){
echo 'second<br/>';
}
protected function thrid(){
echo 'thrid<br/>';
}
public function one(){
return'one'.'<br/>';
}
public function two(){
return "two".'<br/>';
}
public function three(){
return "three".'<br/>';
}
}
跳转和重定向
protected $flag=True;
public function index(){
if ($this->flag){
$this->success('成功','../');
}else{
$this->error('失败','../');
}
}
空方法
public function _empty($name){
return "此方法不存在".$name;
}
空控制器
URL自动转换
如果你创建的控制器是双字母组合那么你需要访问的时候字母之间加下划线进行连接。
如果你想要原样访问URL则需要关闭配置文件中的自动转换。建议默认方式。
默认TRUE改为flase