1 | 配置虚拟主机 |
2 | C:\server\xampp\apache\conf\extra |
3 | <VirtualHost *:80> |
4 | DocumentRoot "C:\server\xampp\htdocs" |
5 | ServerName localhost |
6 | </VirtualHost> |
7 |
|
8 | <VirtualHost *:80> |
9 | DocumentRoot "C:\server\xampp\htdocs\zerg\public" |
10 | ServerName z.com |
11 | </VirtualHost> |
12 | 更改host文件 |
13 | C:\Windows\System32\drivers\etc |
14 |
|
15 |
|
16 | 127.0.0.1 z.com |
17 |
|
18 |
|
19 | //Route::rule('路由表达式','路由地址','请求类型','路由参数(数组)','变量规则(数组)'); |
20 | //Route::rule('hello','sample/Test/hello','GET',['https'=>true ]); |
21 | //Route::get('hello','sample/Test/hello'); |
22 | 1. 特别注意,方法一旦注册路由,原来的path路径方法自动失效。!!!!!!!!!!!! |
23 |
|
24 |
|
25 | 路由里面传递参数:使用“:参数名称” ?name="zhangshan"&age=18 |
26 | Route::post('hello/:id','sample/Test/hello'); |
27 |
|
28 | 1. 方式一: |
29 | public function hello($id, $name,$age){ |
30 | echo $id; |
31 | echo '|'; |
32 | echo $name; |
33 | echo '|'; |
34 | echo $age; |
35 | return "hello qiniujljljlj"; |
36 | } |
37 | 2. 方式二: |
38 | 首先,导入包; |
39 | use think\Request; |
40 | param跟请求方式无关,都能获取到 |
41 | public function hello(){ |
42 | $id = Request::instance()->param('id'); |
43 | $name = Request::instance()->param('name'); |
44 | $age = Request::instance()->param('age'); |
45 | echo $id; |
46 | echo '|'; |
47 | echo $name; |
48 | echo '|'; |
49 | echo $age; |
50 |
|
51 | } |
52 |
|
53 | 获取所有参数一: |
54 | public function hello(){ |
55 | $all = Request::instance()->param(); |
56 | //$all = Request::instance()->get(); 获取get传参数 |
57 | //$all = Request::instance()->post(); 获取post传参 |
58 | //$all = Request::instance()->route(); 获取路由传参 |
59 | var_dump($all); |
60 | } |
61 |
|
62 | 获取所有参数二(通过input助手函数) |
63 | public function hello(){ |
64 | $all = input('param.'); |
65 | var_dump($all); |
66 |
|
67 | } |
68 | 获取所有参数三(通过依赖注入的方法) |
69 | public function hello(Request $request){ |
70 | $all = $request->param(''); |
71 | var_dump($all); |
72 | } |
73 |
|
74 |
|
75 | $data = [ |
76 | // 'name' => 'vendor', |
77 | // 'email' => 'vendor@qq.com', |
78 | // 'id' => $id |
79 | // ]; |
80 | //独立验证方式 |
81 | // $validate = new Validate([ |
82 | // 'name' => 'require|max:10', |
83 | // 'email' => 'email' |
84 | // ]); |
85 |
|
86 | // 验证器方式(封装性更好些,推荐使用) |
87 | // $validate = new IDMustBePostiveInt(); |
88 |
|
89 | // $result = $validate->batch()->check($data); |
90 | // echo $validate->getError(); |
91 | // if($result){ |
92 | // |
93 | // } else { |
94 | // return 'id必须是正整数1111'; |
95 | // } |