The difference between tp5 and tp3

TP5 has made great changes, more flexible, less bloated, and added some exciting functions, such as php7, unittest, etc., but many habits developed under TP3 may need to be changed in tp5.

1 Route changes
define routes in tp3
'URL_ROUTE_RULES' => array( //Define routing rules
	    '/^password(\/)*$/'               => '/Admin/Auth/password',
	),


In this way, both http://xx.com/password and http://xx.com/Admin/Auth/password
can access the same address http://xx.com/Admin/Auth/password

and in tp5 it is No, see line 1251 of Route.php
if (isset(self::$rules['name'][$name]) || isset(self::$rules['name'][$name2])) {
                throw new HttpException(404, 'invalid request:' . str_replace('|', $depr, $url));
            }


If the configured url is defined in the route, direct access is not allowed and an exception will be thrown
'password'            =>  ['admin/auth/password', ['method'=>'get']],


It is normal to use the configured route to access, but it will not jump to admin/auth/password
http://xxx/

password Access with http://xxx/admin/auth/password will report an error
[0] HttpException in Route.php line 1252
Illegal request: admin/auth/password

                $route = [$module, $controller, $action];
                // Check if the address is defined as a route
                $name  = strtolower($module . '/' . Loader::parseName($controller, 1) . '/' . $action);
                $name2 = '';
                if (empty($module) || isset($bind) && $module == $bind) {
                    $name2 = strtolower(Loader::parseName($controller, 1) . '/' . $action);
                }

                if (isset(self::$rules['name'][$name]) || isset(self::$rules['name'][$name2])) {
                    throw new HttpException(404, 'invalid request:' . str_replace('|', $depr, $url));
                }
            }
            return ['type' => 'module', 'module' => $route];
        }



2 Model's find, select and other methods return Model objects, not data. The raw data can be obtained with getData(). It is recommended to define a method in the Model to use db() to query data, and expose the method to the controller call.

3 If you use Model()->save(); to add new data in foreach, you must add ->isUpdate(false), otherwise only the first one will be insert, and the others will become update. This is probably a bug.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326992568&siteId=291194637