Upgrade Guide
http://www.kancloud.cn/manual/thinkphp5/163239
Upgrade from V5.0.1 to V5.0.2
From V5.0.1
the upgrade to the V5.0.2
following things to note:
The following model properties and methods are changed from the original static definition to dynamic definition:
- Properties of the aggregation model
relationModel
- Properties of the Model class
useGlobalScope
- Soft-delete Attribute
deleteTime
properties
- Global query scope method
base
changed to dynamic method
The join
first parameter of the original method and view
method is normalized, supporting the following three usages:
Usage
one: [' prefixed table name ' = ' Alias '] usage two: ' Prefixed table name alias ' Usage three: ' Table name without prefix '
If you have other usage considerations, the following usage is no longer supported:
' no prefix table name aliases '
If you use a null action method, you do not need to _empty
add any parameters to the method, and the acquisition of the current operation name is obtained directly using the Request object's action
function.
Upgrade from V5.0 to V5.0.1
From V5.0
the upgrade to the V5.0.1
following things to note:
- The extended configuration parameter is
extra_config_list
deprecated, except that the extended configuration in addition to the database configuration is placed in the application/extra
directory for automatic recognition loading.
- Model
field
properties do not need to be configured with field types
- Do not use the number placeholder bindings when the Query Builder uses manual parameter bindings
?
, use named parameter bindings
- If you have used the
file_get_contents(‘php://input‘)
Request
method of changing objects to getInput()
get
- File
File
class cancellation md5()
and sha1()
methods, please use hash(‘md5‘)
and hash(‘sha1‘)
method override
Upgrade from V5.0RC4 to V5.0
You can easily upgrade from the RC4 version to the full version, but be aware of the following:
- If a route map (static route) is defined, it is changed to a normal routing rule definition
- After you define a routing rule, the original URL address is forbidden, so please check to see if this is the case
- If the Url_deny_suffix parameter is configured, the Deny_ext parameter setting for the route is changed
- The model Save method returns the value changed to the number of records affected, and the GetID parameter is canceled in the method parameter
- The Request object Controller method returns the hump controller name, and if you use this method to render the template, use loader::p arsename (Request::instance ()->controller ()) to convert
- If the sqlsrv driver is used, the original auto-Convert lowercase data table field does not convert the table field to lowercase by default, change the Pdo::attr_case parameter
- If you deploy an SAE expansion pack in the SAE
- If the Sqlsrv/orace/firebird driver is used, add the original driver file yourself
- When the configuration parameter is read, the environment variable is canceled, and the Env class is required to read the environment variable.
- Change the environment variable definition file to. env from the original PHP array to the INI format definition (supports array mode)
- Load order adjustment for state configuration and extended configuration allows you to change the parameters of an extended configuration in a State profile
- Cancel domain binding to Routing grouping feature
- The success and error method URL parameters of the controller class support passing in an empty string, without any processing
Key points:
The default template directory is all lowercase + glide line specification;
The success, error, and redirect methods of the Controller class do not need to use return;
The model's Save method returns a value that changes to the number of records affected, not the primary key, using the Model->id method to obtain the primary key;
The route definition can no longer be accessed using the original URL address;
Upgrading from the V3.2 version to V5.0
The 3.2 version cannot be upgraded directly to the 5.0 version, here just gives the upgrade guidelines and to use the 3.X
version of the developer faster familiar and get started with this new version. It is also strongly recommended that developers discard previous old thinking patterns as 5.0
a new subversion refactoring version.
Need to abandon the 3. x change of the old thought URL
First to 3. X's not rigorous to the developers to bring the incorrect guidance to apologize, in the 5.0 version of the formal abolition of similar/id/1 way can be obtained through ' get ' to the ' id ' method, strictly speaking such URL is not belong to $_get, can now pass ' Param ' Get, specific use can be requested by partial query.
Changes of the model
The new version of the model query returns the default ' object ', the system adds the ' ToArray ' method by default, and many developers try to use ' ToArray ' to convert the array in ' All ' or ' select ', where they want the developer to understand the ' object ' concept and try to use ' Object ' for the use of data, or using the ' DB ' method for database operations, but also to remind some of the ' abuse ' ' toArray ' developers, ' all ' or ' select ' result is an array of objects that cannot be converted using ' ToArray '.
New Change naming specification
- Directories and filenames are ' lowercase + underlined ' and start with lowercase letters;
- Class Library, function file unification with. php as the suffix;
- The file name of the class is defined in the namespace, and the path to the namespace is consistent with the path of the class library file (including case);
- The class name and the class file name are consistent and are uniformly named with the camel (first capitalization)
Function
- The system is no longer dependent on any functions, but provides helper functions for common operation encapsulation;
- Single-letter function discarded, the default System load helper function, specific reference to the previous Chapter ' helper function ';
Routing
5.0 URL Access no longer supports the normal URL pattern, routing does not support regular route definitions, but instead all changes to rule routing mate variable rules (regular definition), which is no longer detailed here.
Controller
The controller's namespace is adjusted and can be used without inheriting any of the controller classes.
- The namespace of the Application class library is unified for the app (modifiable) instead of the module name;
- The class name of the controller is not suffixed by default
Controller
, and the Enable controller class suffix can be configured with the open controller_suffix
parameter;
- The controller operation method uses
return
the way to return the data rather than the direct output;
- Abolition of the original operation before and after the method;
Version comparison
3.2 Version Controller notation
<?phpnamespace Home\Controller;use Think\Controller;class IndexController extends Controller { public function hello() { echo ‘hello,thinkphp!‘; }}
5.0 Version Controller notation
namespace app\index\controller;class Index { public function index() { return ‘hello,thinkphp!‘; }}
3.2 Versioning Controller naming
IndexController.class.php
5.0 Versioning Controller naming
Index.php
How to properly output the template in the controller
5.0 output The template in the controller, using the following method:
If you inherit think\Controller
, you can use:
return $this->fetch(‘index/hello‘);
If your controller does not inherit think\Controller
, use:
return view(‘index/hello‘);
Model
If not to compare with the old version of the improvement, the model is divided into databases, models, validators three parts, respectively, corresponding to M method, model, automatic verification, at the same time have been strengthened, the following is a brief introduction.
Database
5.0 of database query enhancements, the original need through the model can be used by the chain query directly through the DB Class call, the original M function call can use the DB function, for example:
Version 3.2
M(‘User‘)->where([‘name‘=>‘thinkphp‘])->find();
Version 5.0
db(‘User‘)->where(‘name‘,‘thinkphp‘)->find();
Model
The new version of the model query adds static methods, such as:
User::get(1); User::all();User::where(‘id‘,‘>‘,10)->find();
The model section has enhanced many features, please refer to the "model chapters" for more details.
Automatic validation
Compared to the old version, can be understood as the previous automatic verification and different from the previous validation;
ThinkPHP5.0 validation uses a separate \think\Validate
class or validator for validation, not only for the model, but also for direct invocation in the controller, please refer to the "Validation" section for specific usage rules, which are not covered here.
Configuration file
The new version of the configuration parameters or configuration of a lot of configurations are different from before, it is recommended that you either look at the code, or carefully read through the official development manual, do not because of the configuration of the problem of wasting their entire day of time.
Abnormal
5.0 tolerance for error 0, by default throws an exception to any level of error, and the exception page is redesigned, showing detailed error information for easy debugging.
Abandonment of System constants
5.0 version of the system changes compared to the previous version of a large number of obsolete, users should have the relevant requirements can be defined by their own
Here is the repeal constant
REQUEST_METHOD IS_GET IS_POST IS_PUT IS_DELETE IS_AJAX __EXT__ COMMON_MODULE MODULE_NAME CONTROLLER_NAME ACTION_NAME APP_NAMESPACE APP_DEBUG MODULE_PATH等
Some constants can be obtained in the request, specifically refer to "requesting chapters".
Again, this section is only for the previous use of 3. X version developers quickly understand the 5.0 write, 5.0 of the features also require developers to read through the manual.
Helper functions
5.0
The helper functions and 3.2
versions of the single-letter function are compared as follows:
3.2 version |
5.0 version |
C |
Config |
E |
exception |
G |
Debug |
L |
Lang |
T |
Repeal |
I |
Input |
N |
Repeal |
D |
Model |
M |
Db |
A |
Controller |
R |
Action |
B |
Repeal |
U |
Url |
W |
Widgets |
S |
Cache |
F |
Repeal |
Previous post: helper functions
Thinkphp Upgrade Guide