Thulani Mtshali
Thulani Mtshali

Reputation: 11

Load CSS in codeigniter viewpage only

I am not sure if this is possible, I want to load CSS and JavaScript inside a view not on include.php. I have CSS file loading on include.php and its working fine. Now what I want to do is to load it inside a view page named report.php.

Here is my CSS and JS:

<link rel="stylesheet" href="assets/js/selectboxit/jquery.selectBoxIt.css">
<link rel="stylesheet" href="assets/js/datatables/responsive/css/datatables.responsive.css">
<link rel="stylesheet" href="assets/js/select2/select2-bootstrap.css">

<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Noto+Sans:400,700,400italic">
<link rel="stylesheet" href="assets/css/bootstrap.css">
<link rel="stylesheet" href="assets/css/neon-core.css">

<link rel="stylesheet" href="assets/js/select2/select2.css">

Upvotes: 0

Views: 864

Answers (1)

user4419336
user4419336

Reputation:

If I understand correct what your after. You can load css and js in images from views folder, but you would have to modify the htacces in the application to allow the files. Not recommended though. The htaccess in the application folder says deny all so is blocking the css images and js.

You could just delete the htaccess in the application folder but may be not secure. Up to you.

Auto load url helper.

Main Directory where you should store your assets. IE css js and images

Just examples:

views/common/header.php

<!DOCTYPE HTML>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/css/stylesheet.css');?>">
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/css/bootstrap.css');?>">
</head>
<body>

views/common/footer.php

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo base_url('assets/js/bootstrap.min.js');?>"></script>
<script type="text/javascript" src="<?php echo base_url('assets/js/custom.js');?>"></script>
</body>
</html>

Controller:

<?php 

class Welcome extends CI_Controller {

public function index() {

$this->load->view('common/header');
$this->load->view('content/review');
$this->load->view('common/footer');

}

}

Upvotes: 1

Related Questions