Home  >  Article  >  PHP Framework  >  Solve the problem that ThinkPHP styles cannot be loaded (CSS, JS)

Solve the problem that ThinkPHP styles cannot be loaded (CSS, JS)

藏色散人
藏色散人forward
2021-01-04 17:37:383443browse

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(&#39;APP_NAME&#39;,&#39;APP&#39;);
define(&#39;APP_PATH&#39;,&#39;./APP/&#39;);
define(&#39;APP_DEBUG&#39;, true);
require_once &#39;./ThinkPHP/ThinkPHP.php&#39;;

2. Add the following code to the project configuration file APP/Conf/config.php

&#39;TMPL_PARSE_STRING&#39; => array(        
&#39;__PUBLIC__&#39; =>__ROOT__.&#39;/APP/Tpl/Public&#39;,        
&#39;__JS__&#39; => __ROOT__.&#39;/APP/Tpl/Public/Js&#39;,        
&#39;__CSS__&#39; => __ROOT__.&#39;/APP/Tpl/Public/Css&#39;,
    ),

Previously, the CSS configured here was '__CSS__' => __PUBLIC__.'/Css' Then there was the problem of being unable to load CSS
Solve the problem that ThinkPHP styles cannot be loaded (CSS, JS)

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
Solve the problem that ThinkPHP styles cannot be loaded (CSS, JS)

The file structure is as shown in the figure
Solve the problem that ThinkPHP styles cannot be loaded (CSS, JS)
(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
Solve the problem that ThinkPHP styles cannot be loaded (CSS, JS)

HerePUBLIC is not parsed out

Configure it like later'__CSS__' => __ROOT__.'/APP/Tpl/Public/ Css'

View style
Solve the problem that ThinkPHP styles cannot be loaded (CSS, JS)

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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete