Codeigniter:如何包含javascript文件 [英] Codeigniter: How to include javascript files
问题描述
您好,我刚刚开始使用CodeIgniter框架。我当前的目录结构是
Hello I just started working with CodeIgniter framework. My current directory structure is
Demo(Project name)
+System
+Application
-Controllers
demo.php
+Model
-Views
view_demo.php
-Js
ajax.js
jquery.js
请告诉我如何在view_demo.php中包含.js文件。
Please tell me how to include .js files in view_demo.php.
感谢
Raj
Thanks Raj
推荐答案
您需要使用 base_url
You need to use the base_url()
to include the javascript file in your VIEW.
因此,在view_demo.php文件中:
So, in the view_demo.php file:
<script type="text/javascript" src="<?php echo base_url();?>js/jquery.js" ></script>
<script type="text/javascript" src="<?php echo base_url();?>js/ajax.js" ></script>
您将需要加载URL助手。要加载帮助程序,你需要把你的demo.php控制器:
You will need the URL helper loaded. To load the helper you need to put on your demo.php controller:
$this->load->helper('url');
您也可以在helpers数组的\config\autoload.php上自动加载。
You can also autoload on \config\autoload.php on the helpers array.
有关base_url()的更多信息: http://www.codeigniter.com/user_guide/helpers/url_helper.html#base_url
More info about base_url(): http://www.codeigniter.com/user_guide/helpers/url_helper.html#base_url
这篇关于Codeigniter:如何包含javascript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!