I have created a controller in codeigniter.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Main extends CI_Controller{
public function login(){
$this->load->view('view_login');
}
}
and Below is my view.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Voyager</title>
<link href="../../assets/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link href="../../assets/css/bootstrap.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<table>
<tr>
<td>
<div class="panel panel-heading">
This is Heading
</div>
<input type="submit" class="btn btn-primary">
</td>
</tr>
</table>
<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds. <?php echo (ENVIRONMENT === 'development') ? 'CodeIgniter Version <strong>' . CI_VERSION . '</strong>' : '' ?></p>
<script src="../../assets/js/bootstrap.min.js" type="text/javascript"></script>
<script src="../../assets/js/jquery-3.2.1.min.js" type="text/javascript"></script>
<script src="../../assets/js/bootstrap.js" type="text/javascript"></script>
</body>
</html>
With this Code, Page is rendered but CSS is not applied.
Am I missing something?
Another question which I have is Why do we need helper, I have added code to autoload helper. Why do we need that?
You have to add full path to get CSS styles
CodeIgniter is a MVC structure and file actually call from controller so we can't get actual path so we have to add Full Url of any file so we can not get any type of issue or error.
<link href="<?php echo base_url('assets/css/bootstrap.min.css'); ?>" rel="stylesheet" type="text/css"/>
<link href="<?php echo base_url('assets/css/bootstrap.css'); ?>" rel="stylesheet" type="text/css"/>
And also change your config/config.php file
$config['base_url'] = 'http://localhost/yoursitefolder'; // you can set your working url
Is files really 2 folders up before assets ?
folder1/folder2/assets ???
Go to your config.php and set base_url:
$root=(isset($_SERVER['HTTPS']) ? "https://" : "http://").$_SERVER['HTTP_HOST'];
$root.= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;
and then in your view:
<link href="<?php echo base_url();?>assets/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link href="<?php echo base_url();?>assets/css/bootstrap.css" rel="stylesheet" type="text/css"/>
and same in scripts
<script src="<?php echo base_url();?>assets/js/bootstrap.min.js" type="text/javascript"></script>