Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
68
rated 0 times [  75] [ 7]  / answers: 1 / hits: 100889  / 14 Years ago, fri, october 1, 2010, 12:00:00

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


Please tell me how to include .js files in view_demo.php.



Thanks
Raj


More From » codeigniter

 Answers
28

You need to use the base_url() to include the javascript file in your VIEW.



So, in the view_demo.php file:



<script type=text/javascript src=<?=base_url()?>js/jquery.js ></script>
<script type=text/javascript src=<?=base_url()?>js/ajax.js ></script>


You will need the URL helper loaded. To load the helper you need to put on your demo.php controller:



$this->load->helper('url');


You can also autoload on configautoload.php on the helpers array.



More info about base_url(): http://www.codeigniter.com/user_guide/helpers/url_helper.html#base_url
https://codeigniter.com/user_guide/general/styleguide.html#short-open-tags


[#95441] Wednesday, September 29, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
giovanny

Total Points: 314
Total Questions: 101
Total Answers: 90

Location: Tajikistan
Member since Thu, Apr 14, 2022
2 Years ago
;