Call methods in common. php in the public file in thinkphp

Source: Internet
Author: User
Call the thinkphp common method in the common. php public file in thinkphp

In common. A method is written in php, and an error is always reported when calling the template. the runtime reports an error saying that the cache file corresponding to this template is introduced to common. which line of the method in php has an error, and the entire page is messy, as if no css is introduced
File, but there is no red error in the cache file corresponding to the cache folder in the runtime folder, and part of the code that calls the method in the public file are all interpreted.

This is the code in Commom/common. php.
Header ("content-type: text/html; charset = utf-8 ");

Function sub ($ str ){
$ Length = mb_strlen ($ str, "UTF-8 ");
If ($ length> 20 ){
$ Str = mb_substr ($ str, "UTF-8 ")."...";
}
Return $ str;
}

Function cpy_name ($ id ){
$ Model = M ('cpy _ info ');
$ Result = $ model-> where ("cpy_id = '{$ id}'")-> find ();
Return $ result ['cpy _ name'];
}
?>
Below is the line of code with errors in the template file


{$ V. cpy_id | sub} left a message for {$ v. accept | cpy_name:
{$ V. content}



Or


{$ V. cpy_id | sub =###} to {$ v. accept | cpy_name =:
{$ V. content}



Below is the corresponding cache file code
$ V): ++ $ I; $ mod = ($ I % 2)?>


Pair Message:




Do not call methods in common. what configuration should I change ??
Thinkphp can be called in the past without any problems...
Cainiao asks for advice ............................


Reply to discussion (solution)

Common. php is generally used as a user-defined function library and cannot output anything.

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.