How about introducing external JS and CSS in Ci In codeigniter?
Source: Internet
Author: User
However, when I was using CI today, I forgot that I had never been involved for a long time. I finally decided on the official Chinese website of Ci with their help, post it here for your sharing.
(Another note: I have hidden the index. php file in the URL. It is different from not hiding, but the absolute URL is used in the end)
First, set in the. htaccess file (to hide index. php) as follows:
Rewriteengine on
Rewritecond $1! ^ (Index \. php | images | JS | IMG | CSS | robots \. txt) # Write the resources to be excluded here.
Rewriterule ^ (. *) $ index. php/$1 [l]
. In this way, when I want to introduce JS, the following code is displayed:
<SCRIPT type = "text/JavaScript" src = "url/JS/ajax. js'?> "> </SCRIPT>: note that the URL here is the absolute URL of your website (the absolute URL is http: // domain/JS/ajax. JS, which is called the absolute URL)
That's all. For maintainability, you can also use the base_url of Ci, as shown below:
Go to the Application \ config. php file and set base_url In the config. php file:
$ Config ['base _ url'] = http://www.exiplode/com; // the root directory of your website
After the settings are complete, go to the Controller.
$ This-> load-> helper ('url '),
Then you can introduce it to the specific page of the view layer:
<SCRIPT type = "text/JavaScript" src = '<? = Base_url (). 'js/ajax. js'?> '> </SCRIPT>
Okay, it's so easy to introduce external JS and CSS in CI. If you have any questions, please contact me. QQ: 944597216
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