thinkphp6 文档记录

https://www.kancloud.cn/manual/thinkphp6_0


架构:https://www.kancloud.cn/manual/thinkphp6_0/1037486


ThinkPHP支持传统的MVC

控制器

每个应用下面拥有独立的类库及配置文件,一个应用下面有多个控制器负责响应请求,而每个控制器其实就是一个独立的控制器类。

控制器主要负责请求的接收,并调用相关的模型处理,并最终通过视图输出。严格来说,控制器不应该过多的介入业务逻辑处理。


控制台入口文件,位于项目根目录的think

控制台入口文件用于执行控制台指令,例如:

php think version


URL设计

控制器的修改:

https://www.bilibili.com/video/BV1HA411M7ZW?p=2

6.0的URL访问受路由影响,如果在没有定义或匹配路由的情况下(并且没有开启强制路由模式的话),则是基于:

http://serverName/index.php(或者其它入口文件)/控制器/操作/参数/值…

比如默认的 app/controller/Index.php

<?php
namespace app\controller;

use app\BaseController;

class Index extends BaseController
{
     public function index()
     {
             return "index function";
     }

    public function hello($name = 'ThinkPHP6')
     {
         return 'hello,' . $name;
     }
     public function login()
     {
         return '这是登录';
     }
}

http://192.168.137.128/index.php/index/index

输出: 
index function

http://192.168.137.128/index.php/hello/world
输出: 
hello,world
这个url为啥这样,不可解释。。。。。

http://192.168.137.128/index.php/index/login
这是登录

增加User.php 控制器

<?php
namespace app\controller;

use app\BaseController;

class User extends BaseController
{
     public function index()
     {
             return "user index function";
     }

    public function hello($name = 'ThinkPHP6')
     {
         return 'hello,' . $name;
     }
     public function login()
     {
         return '这是user 登录';
     }
}


http://192.168.137.128/index.php/user/

user index function

http://192.168.137.128/index.php/user/login

这是user 登录

http://192.168.137.128/index.php/user/hello/name/dfdsf

hello,dfdsf

http://192.168.137.128/index.php/user/hello

hello,ThinkPHP6


URL重写

可以通过URL重写隐藏应用的入口文件index.php


最常见的用法,就是将一组URL层次结构字符串,转换成带有查询字符串(query string)的URL

或是反向转换,例如: http://www.somebloghost.com/Blogs/Posts.php?Year=2006&Month=12&Day=10

经过URL重写后,可以变成:

http://www.somebloghost.com/Blogs/2006/12/10/

posted @ 2022-05-23 16:26  katago  阅读(148)  评论(0)    收藏  举报