This article mainly introduces the new ThinkPHP3.1.3 features. For more information about ThinkPHP3.1.3 features, see ThinkPHP3.1.3.
1. Exception Improvement
The new version of ThinkPHP3.1.3 overwrites the Exception class ThinkException (which is actually completely simplified to directly inherit the system Exception class) and encapsulates the Exception logic improvements into the Think class. It mainly involves the appException method of the Think class and the halt function.
In addition, the improved Exception Handling supports capturing system fatal errors. The fatalError method is added to the Think class. The principle is to use
register_shutdown_function(array('Think','fatalError'));
Therefore, the system prompts fatal errors through the unified exception template interface.
2. Support for PDO parameter binding
Because the ThinkPHP3. * version uses a hybrid database driver and supports the PDO mode, the previous version is not optimized for PDO, but is a simple encapsulation. Version 3.1.3 provides complete support for PDO and Sqlarv, because both PDO and sqlsrv Support Parameter binding. (Note that the parameter binding function cannot be used for databases and drivers that do not support parameter binding ).
The system supports parameter binding in two ways:Automatic and manual binding.
Automatic BindingFor write operations (including data addition and update), the framework will automatically convert the data to the parameter binding mode for execution. This part does not need to be processed, sqlsrv supports UTF8 data writing only when values are transferred by parameter binding. However, manual parameter binding is required each time data is written, which makes it quite troublesome. To avoid conflicts with manual parameter binding, Automatic Parameter binding uses md5 encoding for field names.
Manual binding, Usually used for query conditions and the like, and uses bind coherent operation methods, such:
$model->where(array('id'=>':id','name'=>':name'))->bind(array(':id'=>$id,':name'=>$name))->select();
3. Added methods for obtaining variable security.
In earlier versions, variables were securely obtained using the _ post _ get method of the Action class. Although there is no problem, the limitations are that variables can only be obtained in the controller, the new version makes this function an independent shortcut I, which can be used anywhere.
The usage is as follows:
I ('get. id', 0); // GET $ _ GET ['id']. If it does not exist, the default value is 0I ('Post. name', '', 'htmlspecialchars'); // obtain $ _ POST ['name'] and use the htmlspecialchars method to filter I ('id '); // get the id parameter to automatically determine get or postI ('Param. id'); // obtain the id parameter to automatically determine whether get or post is equivalent to I ('put. id'); // obtain the id parameter of the put request
You can also obtain the entire array, for example:
I ('get. '); // get $ _ GET array I ('Post.'); // obtain the $ _ post Array
When the I method is used, the system's VAR_FILTERS and DEFAULT_FILTER filtering configurations are still valid.
4. Multiple where method calls
The where method of the model class supports multiple calls in the array mode, for example:
$model->where(array('a'=>1,'c'=>2))->where(array('a'=>3,'b'=>1))->select();
When multiple where conditions exist, the following conditions are merged into the preceding conditions. The final conditions are equivalent:
$model->where(array('a'=>3,'b'=>1,'c'=>2))->select();
5. The assign Method in the Controller supports consistent operations.
We can use the following in the controller:
$this->assign('name',$name)->assign('email',$email)->display();
Or:
$this->assign(array('name'=>$name,'email'=>$email))->display();