ThinkPHP 6.0 RC 3 release, perfect details, experience optimization

RC3 version of the major improvements and optimization of the system built middleware, usage and improve some experience, and the less frequently used driving out of the way to provide core extension instead.

The main new features

Increase whereWeekdate inquiry

// 查询本周文章
Article::whereWeek('create_time')->select();
// 查询上周文章
Article::whereWeek('create_time', 'last week')->select();
// 查询2019-1-1到2019-1-7的文章
Article::whereWeek('create_time', '2019-1-1')->select();  

Incrementing ID for support Auto Switch

Increment automatically when the acquired ID conversion processing in accordance with the field type of the primary key, rather than the default string type PDO returned.

The current routing rule matching the recording request

Recording the current routing rule object request, by

$request->rule();

Obtaining routing rules that match the actual object for the current request

Increased requireWithoutvalidation rules

It represents a field when no data must be combined in the form of a complete two fields must be filled in an authentication, for example:

'phone' => 'requireWithout:mobile',
'mobile'=> 'requireWithout:phone',

Ext route optimization method and name and URL generation

Increase custom class project

Canceled built think\Controllercontroller base class, the project provides a app\BaseControllercontroller base class easier to customize.

Further projects also provide app\Requestcustom request class, the request may be from the desired properties and methods defined application. It provides app\ExceptionHandlecustom exception class
, easy to customize abnormal takeover process.

URL generation using the object operated

Route class buildUrland urlhelper function return types to think\route\Urlobject instance rather than a string, because the definition of the __toStringmethod, it can be directly output in the template URL string.

echo url('index/hello',['name'=>'think'])->suffix('htm')->domain('blog');

Modifier improvements

Improved support modifier method does not return any data, but the data is provided directly in the modifier

E.g:

class User extends \think\Model
{
	public function setField1Attr($value,$data){
		$this->set('field2', $data['field2']);
		$this->set('field3', $data['field3']);
	}	
}

$user = new User;
$user->field1 = 'value1';
$user->save();

When the actual write to the database will not include field1field data, but will be included field2and field3data.

dump/ haltHelper function to adjust the output supports a number of variables

you can use

dump($var1,$var2,...) 

Mode debugging output multiple variables, the same haltmethod can also support output and debug multiple variables stay of execution.

The latest version will be installed in the installation project symfony/var-dumperexpansion to replace the built-in dumphelper functions, so you can be more powerful output

Associated with automatic updates

Associated togethermethod for automatic update, and delete when you can without usingwith

For example, before writing

$article = Article::with('comments')->find(1);
$article->together(['comments'])->delete();

You can now be written directly

$article = Article::find(1);
$article->together(['comments'])->delete();

Model data set increasing deleteand updatemethods

Data sets can batch update and delete operations (support model event)

// 更新今天的数据
$list = Article::whereDay('create_time')->select();
$list->update(['is_new'=>1]);

// 删除昨天的数据
$list = Article::whereDay('create_time', 'yesterday')->select();
$list->delete();

Model supports dynamic switching table and suffixes

<?php
namespace app\model;

use think\Model;

class Blog extends Model
{
    // 定义默认的表后缀(默认查询中文数据)
    protected $suffix = _cn';
}

Model provides dynamic switching method switchand setSuffix, for example:

// switch方法用于静态查询
Blog::switch('_en')->find();
// setSuffix用于动态设置
$blog = new Blog($data);
$blog->setSuffix('_en')->save();

Notes routing support group belongs to a specified route

Routing packets is defined in the annotation, may be used

<?php
namespace app\controller;

/**
 * @group('blog')
 */
class Blog
{
    /**
     * @param  string $name 数据名称
     * @return mixed
     * @route('hello/:name','get')
     */
	public function hello($name)
    {
    	return 'hello,'.$name;
    }
}

The current controller is automatically added to the route notes bloggrouped below, eventually, will register a blog/hello/:namerouting rule. Like you can set the parameters common to the group routing, for example:

<?php
namespace app\controller;

/**
 * @group('blog')->ext('html')
 *   ->pattern(['id' => '\d+', 'name' => '\w+'])
 * 
 */
class Blog
{
    /**
     * @param  string $name 数据名称
     * @return mixed
     * @route('hello/:name','get')
     */
	public function hello($name)
    {
    	return 'hello,'.$name;
    }
}

If you have already defined in the route definition file bloggrouping can also be added directly to a route the packet, such as:

<?php
namespace app\controller;

class Blog
{
    /**
     * @param  string $name 数据名称
     * @return mixed
     * @route('hello/:name','get')->group('blog')
     */
	public function hello($name)
    {
    	return 'hello,'.$name;
    }
}

Multi-language support group definitions

You can use grouping defined in the definition of multi-language time

return [
    'user'    =>    [
         'welcome'  => '欢迎回来',
         'login' => '用户登录',
         'logout' => '用户登出',
    ]
];

Then use the following way to obtain multi-language variables

Lang::get('user.login');
lang('user.login');

Support for custom add-language file

It can be extend_listset, for example:

'extend_list'    =>    [
    'zh-cn'    => [
        app()->getBasePath() . 'lang\zh-cn\app.php',
        app()->getBasePath() . 'lang\zh-cn\core.php',
    ],
]

Facilitate custom language pack in extension
, and now supports the use of language file YMLformat definition

Improved cache tag

Increasing the TagSetclass, tagmethod support incoming array, while a plurality of tabs for

Cache::tag('tag')->set('name1','value1');
Cache::tag('tag')->set('name2','value2');

// 清除tag标签的缓存数据
Cache::tag('tag')->clear();

And to support the specification of multiple cache tag operation

Cache::tag(['tag1', 'tag2'])->set('name1', 'value1');
Cache::tag(['tag1', 'tag2'])->set('name2', 'value2');

// 清除多个标签的缓存数据
Cache::tag(['tag1','tag2'])->clear();

A cache can be added to the label

Cache::tag('tag')->append('name3');

Increase cache class pushmethod

Adding elements to an array cache

Cache::set('name', [1,2,3]);
Cache::push('name', 4);
Cache::get('name'); // [1,2,3,4]

Cookie save time support DateTimeInterface

Increase form token middleware

The controller supports __call method

Increase deny_app_listconfiguration parameters

You can configure a list of applications prohibit direct access

Controller middleware improvements

Controller middleware onlyand exceptdefine case-insensitive

app_mapPan-mapping application that supports the specified

You may be app_mapdefined to resolve the specified application pan configuration application, for example:

'app_map' => [
    'think'  =>  'admin',  // 把admin应用映射为think
   // ... 其它应用映射定义
    '*' => 'home', // 其它应用解析到home
],

Bug fixes

  • Precision floating-point correction parameter binding issue
  • Correction soft delete
  • Correction model database connection
  • CorrectionRedirectResponse
  • Correction Session class flushmethod
  • JSON field correction parameter binding
  • Correction make:controllercommand generation
  • Correction Cache class getmethod defaults
  • Corrected binding domain
  • Dynamic Correction association model getter
  • Correction Model dateFormatProperties Methods
  • Correction url generate support for multiple entries
  • Correction ini configuration file format Boolean value problem
  • Correction routing latency issues to resolve global configuration invalid
  • Amended route cache problems
  • Correction related updateoperations
  • Correction Relation::$selfRelationby default null, resulting Relation::isSelfRelation()method error
  • Correcting rediscache drive
  • Smart correction event subscription observemethods
  • Correction field defines the model of the date of issue invalid query
  • Correction Console class getNamespacesmethod
  • Correcting wherethe lack of incoming Query object query method when the binddata problem
  • Correction request class methodmethod
  • Correction route:listinstruction
  • Correction Collectionclass loadmethod
  • Correction redisdrive port type
  • Correction sessiondata serialization processing problems using JSON
  • Correction packet routing resolve merge
  • The modified model hiddenmethod to hide problems associated with model
  • Correction associated with the query associated with key empty error
  • Fixed 204 returns a response status code is determined
  • Amendments Requestclass hasmethods envand sessionsupport
  • Correction provider.phpfile is invalid problem
  • Correcting some of the problems associated with the query
  • Correction validate helper function that supports the specified validator class
  • Correcting validation class getValidateTypemethod
  • To open a separate entrance amendments debugging mode
  • Composer application load correction

Usage adjustment

  • Page tracemiddleware valid only in debug mode
    , and without setting environment variables
  • SocketLog drive out of the core
  • PostgreSQL, SqliteAnd SqlServerdriven out of the core, instead extended
  • Cancel built think\Controllerthe base class
  • YaconfOut of the core into the support extendedthink-yaconf
  • Fields changed to exclude withoutFieldmethods
  • Cancel useGlobalScopemethod for increasing withoutGlobalScopemethod
  • Change the default location of the generated middleware
  • Load default language packs without opening multiple languages ​​Middleware
  • CookieClass recovery getand hasmethods support
  • tokenHelper function adjustment
  • Caching global request parameter adjustment
  • Unified middleware call parameter passing, do not support the :split of mass participation
  • Unified cache data serialized after storage

Abandoned usage

  • Cancel multilingual auto_detectconfiguration
  • Cancel sessionclass auto_startconfiguration parameters and bootmethods
  • Abandoned Wherearray object query
  • Cancellation observer model events
  • Cancellation JumpResponseand success/ error/ resultother methods and helper
  • Cancel query expression parsing and extended think\db\Expressionclass
  • Abandoned model AutoComplete feature, use an alternative model events
  • Cancellation cookieof prefixparameters
  • Cancel a series of helper functions deprecated
  • Cancel optimize:facadeoptimize:modelinstruction was changed to expansion mode
  • Cancel command line URL
  • Delete Configclasses __get and  __isset methods

Guess you like

Origin www.oschina.net/news/107171/thinkphp-6-0-rc3-released