Given the file structure and using WAMP
www
application
\views
\templates
header.php
assets
\js
index.js
\css
index.css
I was trying to follow along the example given in this solution, Codeigniter: How to include javascript files, however I have been unsuccessful.
header.php
<html>
<head>
<?php $this->load->helper('url');?>
<script type="text/javascript" src="<?php echo base_url();?>assets/js/index.js" ></script>
<title>CodeIgniter Tutorial</title>
</head>
<body>
<h1><?php echo $title ?></h1>
the error thrown in the browser is
GET http://localhost/index.php/localhost/assets/js/index.js 404 (Not Found)
header.php is being called, as it's the my only php file with a js reference, sorry if I misinterpreted the other guy's solution I really can't understand why it's not working
Locate your httpd.conf
file.
In my case it is located in C:\wamp\bin\apache\apache2.4.9\conf
Please uncomment LoadModule rewrite_module modules/mod_rewrite.so
In your config.php located in application\config\config.php
set the following value.
$config['base_url'] = '';
One of the reason to answer why I uncomment mod_rewrite.so
, here's the explaination:
On constants.php
below config.php
Open constants.php
and write a piece of this code for your ease
define('ROUTE_STIE_PATH','`http://localhost/yoursitename/`');
define('ADMIN_CSS_DIR_FULL_PATH',ROUTE_STIE_PATH.'assets/css/');
define('ADMIN_JS_DIR_FULL_PATH',ROUTE_STIE_PATH.'assets/js/');
on header
<script src="<?php echo ADMIN_JS_DIR_FULL_PATH; ?>index.js" type="text/javascript"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With