路由规则:
1. 路由可选参数 [] $为结束
return [ // 路由参数name为可选 'hello/[:name]$' => 'index/hello', ];
2. 闭包路由
Route::rule('hello/:name', function ($name) {
return 'Hello,' . $name . '!';
});3. 后缀参数
return [ // 定义路由的请求类型和后缀 'hello/[:name]' => ['index/hello', ['method' => 'get', 'ext' => 'html']], ];
4. 变量路由
return [
'blog/:year/:month' => ['blog/archive', ['method' => 'get'], ['year' => '\d{4}', 'month' => '\d{2}']],
'blog/:id' => ['blog/get', ['method' => 'get'], ['id' => '\d+']],
'blog/:name' => ['blog/read', ['method' => 'get'], ['name' => '\w+']],
];5. 把变量规则统一定义
return [
// 全局变量规则定义
'__pattern__' => [
'name' => '\w+',
'id' => '\d+',
'year' => '\d{4}',
'month' => '\d{2}',
],
// 路由规则定义
'blog/:id' => 'blog/get',
'blog/:name' => 'blog/read',
'blog-<year>-<month>' => 'blog/archive',
];6. 路由分组
return [
'[blog]' => [
':year/:month' => ['blog/archive', ['method' => 'get'], ['year' => '\d{4}', 'month' => '\d{2}']],
':id' => ['blog/get', ['method' => 'get'], ['id' => '\d+']],
':name' => ['blog/read', ['method' => 'get'], ['name' => '\w+']],
],
];7. 页面信息便利
{volist name="list" key="k" id="v" mod="2"}
{eq name="mod" value="0"}
{/eq}
{/volist}8. 数据接收
Request $request
a. $request->post();
b. Request::instance()->post();
c. input('post.');register_shutdown_function 定义:该函数是来注册一个会在PHP中止时执行的函数 以前是当做析构函数再用,现在主要用于报错机制,出现错误,记录进日志
register_shutdown_function()
register_shutdown_function("errorCheck");
function errorCheck(){
$error=error_get_last();
if ($error){
//创建日志
hvlog(json_encode($error), 'app_error');
}
}2. 修改密码:
$info = $admin_db->where(array('userid'=>$userid))->field('password,encrypt')->find();
if(password(I('post.old_password'), $info['encrypt']) !== $info['password'] ) $this->error('旧密码输入错误');
if(I('post.new_password')) {
$state = $admin_db->editPassword($userid, I('post.new_password'));
if(!$state) $this->error('密码修改失败');
}
$this->success('密码修改该成功,请使用新密码重新登录', U('Index/logout'));

