I am new to CodeIgniter, and currently practicing it because we have to use this framework for a huge project. Right now I'm creating a sample project with bootstrap. It doesn't work when I download bootstrap, put it in a folder with the same level as application and system folders. But if I use bootstrap's CDN, it actually works but I don't want to do that because in our major project we will be using a custom bootstrap template which does not have a CDN link.
At first, I thought it was the base_url, but it works when I link it with an image.
note:
- I removed the usage of index.php
- I also tried putting the css and js folders inside an "assets" folder, doesn't work either
the root folder directory of ci_sample:
- application
- system
- css
bootstrap.css
- js
jquery.js
bootstrap.js
- .htaccess
my changes at config.php:
Code:
$config['base_url'] = 'http://localhost/ci_sample/';
$config['index_page'] = '';
changes at autoload.php:
Code:
$autoload['helper'] = array('url', 'html');
.htaccess at root:
Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
pages controller (Pages.php):
Code:
<?php
class Pages extends CI_Controller{
public function view($page = 'home'){
if(!file_exists(APPPATH.'views/pages/'.$page.'.php')){
show_404();
}
$data['title'] = ucfirst($page);
$this->load->helper('url');
$this->load->view('pages/'.$page, $data);
}
}
routes.php:
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['default_controller'] = 'pages/view';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
views/home.php
Code:
<html>
<head>
<link rel="stylsheet" href="<?php echo base_url();?>css/bootstrap.css" type="text/css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-6">
<h1>Hello</h1>
</div>
<div class="col-md-6">
<img src="<?php echo base_url();?>images/fb4.jpg">
</div>
</div>
</div>
</body>
<footer>
<script src="<?php echo base_url();?>js/jquery.js"></script>
<script src="<?php echo base_url();?>js/bootstrap.js"></script>
</footer>
</html>