Difference in arrayserialize processing in the thinkphpconfig file

Source: Internet
Author: User
The difference between arrayserialize processing in the thinkphpconfig file is config. php defines a constant of the array type. to serialize the array serialize, you need to write 'error _ code' = & gt; serialize (array (& nbsp; what is the difference between array serialize processing in the & thinkphp config file?
Define a constant of the array type in config. php. if you need to serialize the array serialize, you need to write
'Error _ code' => serialize (array (
// Client Error 4xx
400 => 'bad request ',
401 => 'authorized ',
...
)),
In use
$ERROR_COEDE = unserialize(C("ERROR_CODE"));return $ERROR_COEDE[$code];


This is OK. ERROR_CODE also does not change.

In the second case, if the array content is large and needs to be extracted to an independent file, use
Require (dirname (_ FILE _). '/code. php ');
Load ERROR_CODE of code. php
 

You can also use unserialize for deserialization.
However, if you set
'Default _ filter' => 'htmlspecialchars ',
Pay attention to it. Because thinkph checks whether this configuration parameter exists and uses the function corresponding to this configuration to process the content of code. php, the obtained content is escaped by htmlspecialchars. For example, double quotation marks "are converted \".

Therefore, remove the escape characters and deserialize them. otherwise, false is returned.
$HTTP_CODE = stripslashes(ERROR_CODE); $ERROR_ARR = unserialize($HTTP_CODE);

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.