ThinkPHP3.1.3 version new features overview _php instances

Source: Internet
Author: User
ThinkPHP3.1.3 version has some features, it is worth paying attention to, the following simple.

1, abnormal aspects of the improvement

The new version of ThinkPHP3.1.3 overrides the Exception class thinkexception (in fact, it is completely simplified into a direct inheritance system exception Class), and the exception logic improvements are encapsulated in the think class. It mainly involves the Appexception method and halt function of think class.
and the improved exception handling supports the system fatal error capture, the Think class adds the FatalError method, the principle is to use the

Register_shutdown_function (Array (' Think ', ' fatalerror '));

This makes it possible to make system fatal errors through a unified exception template interface friendly hints.

2. Support for PDO parameter binding

Because the thinkphp3.* version uses a hybrid database driver and also supports PDO, the previous version is not optimized for PDO, but is simply encapsulated. The 3.1.3 version provides support for PDO and SQLARV because both PDO and SQLSRV support parameter binding operations (note that database and driver that do not support parameter binding cannot use the parameter binding feature).

There are two types of system support for parameter binding operations: automatic binding and manual binding .

Automatic binding is for write operations (including new and updated data), the framework will automatically convert the relevant data into a parameter binding method of execution, this part does not require additional processing, because sqlsrv only in the way of parameter binding to support UTF8 data writing, However, it is cumbersome to use manual parameter bindings for each write data. To avoid conflicts with manual parameter binding, automatic parameter binding takes the form of encoding the field name MD5.

Manual binding , commonly used for query conditions, and with bind-coherent operations, such as:

$model->where (' id ' = ' + ': id ', ' name ' = ': Name '))->bind (Array (': id ' = ' $id, ': name ' = ' = $name))- >select ();


3. Increase the safe access method of variable

The previous version through the action class _post _get and other methods to secure the variable, although no problem, but the limitation is only in the controller to get the variable, the new version of the function as a quick method I, can be used anywhere.
Here's how to use it:

I (' Get.id ', 0); Get $_get[' id '] if it does not exist then the default is 0I (' post.name ', ' ', ' htmlspecialchars '); Get $_post[' name '] using the Htmlspecialchars method to filter I (' id '); Get ID parameter automatically judge get or posti (' param.id '); Get ID parameter automatically judge get or post and the above usage equivalent I (' put.id '); Gets the ID parameter of the PUT request

It also supports getting the entire array, for example:

I (' get. '); Gets the $_get array I (' post. '); Get $_post Array

In the case of the I method, the var_filters and default_filter filtering configurations of the system are still valid.

4. Multiple invocations of the Where method

The Where method of the model class can support multiple invocations of the array mode, for example:

$model->where (Array (' A ' =>1, ' C ' =>2))->where (Array (' A ' =>3, ' B ' =>1))->select ();

When multiple where conditions are applied, the following conditions are merged into the preceding conditions, and the final condition is equivalent to:

$model->where (Array (' A ' =>3, ' B ' =>1, ' C ' =>2))->select ();


5. The Assign method in the controller supports coherent operation

We can use it in the controller:

$this->assign (' name ', $name)->assign (' email ', $email)->display ();

Or:

$this->assign (Array (' name ' = = $name, ' email ' + $email))->display ();
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.