Home > Article > PHP Framework > Solve the problem that ThinkPHP styles cannot be loaded (CSS, JS)
The following thinkphp framework tutorial column will introduce to you how to solve the problem of ThinkPHP style failure to load (CSS, JS). I hope it will be helpful to friends in need!
1. Project entry file index.php
<?php define('APP_NAME','APP'); define('APP_PATH','./APP/'); define('APP_DEBUG', true); require_once './ThinkPHP/ThinkPHP.php';
2. Add the following code to the project configuration file APP/Conf/config.php
'TMPL_PARSE_STRING' => array( '__PUBLIC__' =>__ROOT__.'/APP/Tpl/Public', '__JS__' => __ROOT__.'/APP/Tpl/Public/Js', '__CSS__' => __ROOT__.'/APP/Tpl/Public/Css', ),
Previously, the CSS configured here was '__CSS__' => __PUBLIC__.'/Css'
Then there was the problem of being unable to load CSS
ROOT is a system constant, indicating the root directory address of the website. For example, my localhost is set to E:\www In this place, and then create the ThinkPHPbbs project in E:\www\ThinkPHPbbs, then ROOT indicates localhost/ThinkPHPbbs
JS settings are the same as
3 .Configure html
CSS:<link rel="stylesheet" href="__CSS__/lrtk.css" type="text/css">
JS :<script src="__JS__/jquery.min.js"></script>
The normal loading effect is as shown
The file structure is as shown in the figure
(The red crosses in front of some folders will not affect the entire operation, the editor is zend studio)
It is recommended that if you encounter a situation where the style cannot be loaded If there is a problem, you can check the path of the link. For example, I configured it as follows'__CSS__' => __PUBLIC__.'/Css'
If you check the web page elements, it will be displayed as follows
HerePUBLIC is not parsed out
Configure it like later'__CSS__' => __ROOT__.'/APP/Tpl/Public/ Css'
View style
Parse normally
The above is the detailed content of Solve the problem that ThinkPHP styles cannot be loaded (CSS, JS). For more information, please follow other related articles on the PHP Chinese website!