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.