2

This may be a duplicate question but I'm new in codeigniter. My question is whenever I tried $this->load->view('anyhtmlpage.html') it never loads the required css and js files.

Condition: All files in view must contain pure HTML (no php).

The base url is: $config['base_url'] = 'http://localhost:8081/SVN_propertybooking/branches/dev/Admin/';

I also defined $route['default_controller'] = 'Admin'; in routes.php and $autoload['helper'] = array('form', 'url'); in autoload.php

And when I tried like this <link href="../assets/css/bootstrap.min.css" rel="stylesheet"> after $this->load->view('anyhtmlpage.html') it loads the css and js files.

But more amazing is when I write header('location:'.base_url()); it loads all css and js files.

So what is missing here, help please.

Folder structure:

enter image description here

2 Answers 2

2

Load view should be

$this->load->view('anyhtmlpage'); # File name should be anyhtmlpage.php 

and CSS will be

<link href="<?php echo base_url() ?>assets/css/bootstrap.min.css" rel="stylesheet">

As above code your css should place like this

application
assets
    - css
        - bootstrap.min.css
    - js
        - ab.js
    - images
        - no_image_found.png
system
index.php
Sign up to request clarification or add additional context in comments.

8 Comments

but what if I require only pure html pages in my view folder
So no harm if you add .php as extension
sir this is the requirement, so can we make some adjustment (if possible). Else .php is the last option to me
@VilasGalave there is no any change in there. All what you have to do is just change extension to .php. this will works. Try once. Will wait for you on here. ok
Best way to explain this answer!!specially folder structure
|
1

In CI You can't load js and Css file using load->view

you need to write direct in your template file or header file.

<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/style.css">
<script type='text/javascript' src="<?php echo base_url(); ?>js/jquery.min.js"></script>

load url helper in controller

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

You can check this tutorial for further help :: How to use css and js in CI

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.