ThinkPHP 3.2 版本升级了哪些内容_PHP
前言
ThinkPHP 3.2 基于 ThinkPHP 3.1 的基础上有许多的变化,我觉得这个版本应该设立为 ThinkPHP 4.0 而不是什么 3.2。如果你在使用 ThinkPHP 3.1 请勿贸然迁移升级,这可不是简单的覆盖下文件就安然无恙的事情。
1. PHP 的版本
ThinkPHP 3.2 要求 PHP 5.3 以上的版本,而 ThinkPHP 3.1 只需要 PHP 5.2 就好了
2. 程序文件夹的修改
ThinkPHP 3.2 使用 Application 作为程序文件夹,而 ThinkPHP 3.1 则是用 app 作为程序文件夹。
3. 不同分组设定的升级
建议以后开发尽量不要做分组,要不然针对分组,有不少要处理的地方,这里只是介绍未分组的情况,有做分组的朋友,请上官方文档寻找答案。
ThinkPHP 3.2 设置了一个 Home 目录,很多文件都将迁移到 Home 目录中。
代码如下:
App/Common/common.php => Application/Home/Common/function.php
App/Common/extend.php => Application/Home/Common/extend.php(假设存在定义的话)
App/Conf/Config.php => Application/Home/Conf/config.php
App/Lang/zh-cn/common.php => Application/Home/Lang/zh-cn.php(假设存在的话)
App/Lib/Action => Application/Home/Action
App/Lib/Model => Application/Home/Model
App/Tpl => Application/Home/View
注意,因为 Home 目录的出现,你需要修改你的 .htaccess 文件为
代码如下:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/home/$1 [QSA,PT,L]
否则,将会出现模块找不到的错误。
新的目录对 Action 和 Tpl 进行了重新命名,分别为 Controller 和 View,这样更加直观的体现了 MVC 的文件夹的部署方式。对于那些保留了 Action 的朋友,可以修改 Application/Common/config.php 中的信息:
代码如下:
'DEFAULT_C_LAYER' => 'Action', // 默认的控制器层名称
'MODULE_ALLOW_LIST' => array('Home','Admin',...), // 配置你原来的分组列表
'DEFAULT_MODULE' => 'Home', // 配置你原来的默认分组
4. 系统配置参数的变动
ThinkPHP 3.2 废弃了以下系统配置参数
代码如下:
APP_GROUP_LIST
APP_GROUP_MODE
APP_AUTOLOAD_PATH
APP_TAGS_ON
APP_GROUP_PATH
DEFAULT_APP
DEFAULT_GROUP
VAR_GROUP
LOG_DEST
LOG_EXTRA
修改了以下配置参数
代码如下:
DEFAULT_MODULE => DEFAULT_CONTROLLER
5. 命名空间
ThinkPHP 3.2 添加了命名空间,把项目的Application/Home/Action目录下面的所有文件,头部添加如下代码(必须是除注释以外的第一行):
代码如下:
namespace Home\Action;
use Think\Action;
如果你的项目使用了控制器分层的话,需要对每个分层的类库文件添加类似的代码,例如有定义Event分层的话,需要在头部添加:
代码如下:
namespace Home\Event;
use Think\Action;
把项目的Application/Home/Model目录下面的所有文件,头部添加如下代码(必须是除注释以为的第一行):
代码如下:
namespace Home\Model;
use Think\Model;
如果你的项目使用了模型分层的话,需要对每个分层的类库文件添加类似的代码,例如如果你有Service分层,需要在头部添加:
代码如下:
namespace Home\Service;
use Think\Model;
6. 方法调整
控制器类Think\Controller或者Think\Action的下列方法已经废除:
废除方法 | 替代方法 |
---|---|
_get('id') | I('get.id') |
_post('id') | I('post.id') |
_put('id') | I('put.id') |
_param('id') | I('id') |
_request('id') | I('request.id') |
_cookie('id') | I('cookie.id') |
7. 常量调整
下列常量已经废除:
APP_NAME // 3.2版本中无需再定义该常量
__GROUP__ // 3.2版本中可以用__MODULE__ 表示模块的URL地址
GROUP_NAME //3.2版本中可以用 MODULE_NAME 获取当前模块名
MODE_NAME // 3.2版本中模式扩展已经废弃,参考下面的模式调整部分
这样就基本上完成了迁移,如果中间还有一些修改的话,请上官方文档寻找答案。
以上就是本文所述关于ThinkPHP3.2发生的变化了,希望对大家能够有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

To update the curl version under Linux, you can follow the steps below: Check the current curl version: First, you need to determine the curl version installed in the current system. Open a terminal and execute the following command: curl --version This command will display the current curl version information. Confirm available curl version: Before updating curl, you need to confirm the latest version available. You can visit curl's official website (curl.haxx.se) or related software sources to find the latest version of curl. Download the curl source code: Using curl or a browser, download the source code file for the curl version of your choice (usually .tar.gz or .tar.bz2

How to easily check the installed version of Oracle requires specific code examples. As a software widely used in enterprise-level database management systems, the Oracle database has many versions and different installation methods. In our daily work, we often need to check the installed version of the Oracle database for corresponding operations and maintenance. This article will introduce how to easily check the installed version of Oracle and give specific code examples. Method 1: Through SQL query in the Oracle database, we can

Checking the Kylin operating system version and kernel version In the Kirin operating system, knowing how to check the system version and kernel version is the basis for system management and maintenance. Method 1 to check the Kylin operating system version: Use the /etc/.kyinfo file. To check the Kylin operating system version, you can check the /etc/.kyinfo file. This file contains operating system version information. Execute the following command: cat/etc/.kyinfo This command will display detailed version information of the operating system. Method 2: Use the /etc/issue file Another way to check the operating system version is by looking at the /etc/issue file. This file also provides version information, but may not be as good as the .kyinfo file

Regarding Llama3, new test results have been released - the large model evaluation community LMSYS released a large model ranking list. Llama3 ranked fifth, and tied for first place with GPT-4 in the English category. The picture is different from other benchmarks. This list is based on one-on-one battles between models, and the evaluators from all over the network make their own propositions and scores. In the end, Llama3 ranked fifth on the list, followed by three different versions of GPT-4 and Claude3 Super Cup Opus. In the English single list, Llama3 overtook Claude and tied with GPT-4. Regarding this result, Meta’s chief scientist LeCun was very happy and forwarded the tweet and

Done in one minute: How to update the pip version, specific code examples are required. With the rapid development of Python, pip has become a standard tool for Python package management. However, as time goes by, pip versions are constantly updated. In order to be able to use the latest features and fix possible security vulnerabilities, it is very important to update the pip version. This article will explain how to quickly update pip in one minute and provide specific code examples. First, we need to open a command line window. In Windows systems, you can use

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

The DP interface is an important interface cable in the computer. When using the computer, many users want to know how to check whether the DP interface is 1.2 or 1.4. In fact, they only need to check it in GPU-Z. How to determine whether the dp interface is 1.2 or 1.4: 1. First, select "Advanced" in GPU-Z. 2. Look at "Monitor1" in "General" under "Advanced", you can see the two items "LinkRate (current)" and "Lanes (current)". 3. Finally, if 8.1Gbps×4 is displayed, it means DP1.3 version or above, usually DP1.4. If it is 5.4Gbps×4, then
