Share EncyclopediaHome EncyclopediaCategories Switch Channel

Changes in models

2026-04-05 03:101310NameNetworking

Thinkphp g method

The first is to state that the chapter is not intended to guide the upgrading of the old project to 5. 0, but rather to use the new version of 3. X version, which is more quickly familiarized and hands on by developers. At the same time, it is strongly recommended that developers abandon the old thinking pattern, as 5. 0 is a completely new subversive version。

3. X old ideas need to be abandoned

Changes in urls

First of all, i apologize for the imprudent guidance given to developers by 3. X. The formal abolition of similar /id/1 methods in version 5. 0 can be obtained `id' through `get ' , which, strictly speaking, url does not belong to $ get and can now be obtained through `param ' , which can be consulted in part of the request。

Changes in models

The new version of the model query returns the default `object ' , the system by default adds the `toarray' method, and many developers in 'all' or 'self' try to convert groups by using 'toarray', hoping that developers will understand the concept of `object', try to use `object' for data, or use `db' for database operations, and also remind some `overwhelm' developers, 'all' or 'self' result in a cluster of objects that cannot be converted using 'toarray'。

Changes in the new edition

Naming code

Catalogues and filenames are based on `case + underlined ' and begin with lowercase letters; library, function files are unified and suffixed with . Php; category files are defined by namespace, and the path to name space and library files are consistent (including case & case); class names and category filenames are consistent, and the hump method (heading capital) is applied uniformly

Functions

The system is no longer dependent on any function but provides an assistant function for a commonly used operational envelope; a single-letter function is abandoned, the default system loads the assistant function, with specific reference to the previous section `associate function '

Route

The url access of 5. 0 no longer supports the normal url model, and the route does not support the definition of the regular route, but is changed to the way the rule route corresponds to the variable rule (recipient definition), which is not repeated here。

Controller

The namespace of the controller has been adjusted and it is possible to inherit no control class。

Apply the namespace of the library to merge to app (modifiable) instead of the module name; the control class name is defaulted on the controller suffix and can be configured to open the controller suffix parameter to enable the controller class suffix; the controller operation returns data in a return way instead of directly output; the original pre- and post-operation method is abolished

Version comparison

3. 2 version controller

I'm sorry, sirNtroller.
{public function hello()
echo'hello, thinkphp!';
♪ i'm sorry ♪
♪ i'm sorry ♪

5. 0 version controller

Namespace app\index\controller;class index
{public fight index()
turn 'hello, thinkphp!
♪ i'm sorry ♪
♪ i'm sorry ♪

3. 2 version controller name

Indexcontroller. Class. Php

5. 0 version controller name

Index. Php

** correct output template in controller**

5. 0 in the controller output template using the following methods:

If you succeed to the think\controller, you can use:

Return $this->fetch ('index/hello');

If you don't inherit the controller, think about contractor, use:

(a) return view ('index/hello');

Model

Viggle ai video

Powerful ai-powered animation tool and image-to-video ai general.

Download

If a comparison is made with the improvements made in the old version, the model is divided into three parts: databases, models, and certifiers, which correspond to m methods, models, auto-certification, and are enhanced, as briefly described below。

Database

5. 0 the database query function is enhanced by a chain query that originally required a model to be used, which can be called directly through the db category and the original m function can be called instead of the db function, e. G.:

Version 3. 2

M('user') - >where (['name'=>'thinkphp']) - >find ();

Version 5. 0

Db('user') - >where (`name','thinkphp') - >find();

Model

New versions of model queries add static methods such as:

User: :get (1);
user: all(); user: where: ('id','',' 10)->find();

The model section has enhanced many functions, as detailed in the model chapter。

Autovalidation

Compared to the old version, it could be understood as an automatic and different from the previous version

Thinkphp5. 0 for authentication using an independent \think\validate class or a certifier not only applies to models, but can also be called directly in the controller. For specific rules, please refer to the “validation” section and not dwell here。

Profile

Many configuration parameters or configuration levels are different from previous ones, and it is suggested that you should either look at the code or read the official development manual carefully, and not waste all day on your configuration。

Unusual

5. 0 with zero tolerance for errors, errors at any level are thrown out by default and the anomaly page is redesigned to display detailed error information to facilitate debugging。

Dismissed system constant

5. 0 releases have been heavily discarded from the system relative to previous versions, and users can define themselves if they have relevant needs

Here's to abolish the constant

Request method is get is post is put is delete is ajax ext comon module module name controller name accion name app name app namspace app dbug module path

Some constants are available in request, with specific reference to the “request chapter”。

Note: restate that this section is written only for a quick understanding of 5. 0 by the previous developers using 3. X version, and that the specific function of 5. 0 also requires that developers read the manual。

Assistant functions

5. 0 the assistant function and the single letter function of version 3. 2 are compared as follows:

C config

Other organiser

G debug

Lang

T abolition

I input

N abolition

D model

M db

A controller

Raction

B abolition

U url

W widget

Scache

F abolition

Like 0
Report
Favorite 0
Tip 0
Comment 0
Share 4
MoreRelated Comments
No comments yet, be the first to comment
Old things make dreams. They write love letters for their childhood with junk
Did you ever do that when you were a kid -- you saved a drawer of popsicle sticks to build a small house? The power of the stock, "snatching for the world", has been hidden in the hearts of many。In henan, there's an old man named dachang, who's trying to make it real. Over the past 15 years, nearly 30,000 strangled cans, without entering the recycling site, have become his family's private convoyland cruisers, helicopters, even tanks. Neig

0评论2026-08-0991