1.入口文件的绑定
thinkphp是一个单入口框架,它所有的请求都通过public/index.php进入
在入口文件(public/index.php)中添加如下代码,他就会通过index.php,自动访问home模块
// 定义应用目录
define('APP_PATH', __DIR__ . '/../application/');
// 绑定到index模块
define('BIND_MODULE','home');
// 加载框架引导文件
require __DIR__ . '/../thinkphp/start.php';
2.URL
thinkphp/convention.php:找到url_route_on和url_route_must,是配置路由是否开启和是否强制使用路由。
我们使用默认配置,然后找到public/route.php文件
return [
'test/:id' => 'index/test'
];
3.Request&Response
Request统一处理请求和获取请求信息
Response对象负责输出客户端或者浏览器响应
3.1获得Request对象
3.1.1助手函数request()
3.1.2Request类来获取实例
3.1.3直接注入Request对象
3.1.4具体代码
<?php
namespace api\index\controller;
use think\Request;
class Index
{
public function index(Request $request)
{
# 获取浏览器输入框的值
dump($request->domain());
dump($request->pathinfo());
dump($request->path());
# 请求类型
dump($request->method());
dump($request->isGet());
dump($request->isPost());
dump($request->isAjax());
# 请求的参数
dump($request->get());
dump($request->param());
dump($request->post());
//session('name', 'onestopweb');
//cookie('email', '[email protected]');
//session(null);
//cookie('email',null);
dump($request->session());
dump($request->cookie());
dump($request->param('type'));
dump($request->cookie('email'));
# 获取模块 控制器 操作
dump($request->module());
dump($request->controller());
dump($request->action());
# 获取URL
dump($request->url());
dump($request->baseUrl());
}
}
4.数据库
tp5.0
助手函数废除了单字母函数,改用助手函数