hi i am facing problem in loading css file.
<?php //if ( ! defined("BASEPATH")) exit("No direct script access allowed");
class Controller2 extends CI_Controller
{
function index()
{
if ($this->input->post('button'))
$this->test();
else
$this->load->view('2');
}
function test()
{
$this->load->view('2');
}
}
?>
when i first call my controller index function it is loading view “2” with proper html and css but when i press a button inside my “2” view my controller is calling another function TEST but this time test is not loading the same view with css.
can anyone solve this?
Using my psychic powers, because you’ve provided very little, I believe the answer is that you are providing a relative path to your CSS file.
In your view, you need to make sure that the CSS file is referenced absolutely. Examples:
Wrong
This will only work if the path stays the same. However, your path is changing from
/controller2to/controller2/test, which means on the second page, the browser is going to look for/controller2/style.cssfor the first method, and/controller2/test/style.cssfor the second.Correct
Now, the output will be an absolute path to the stylesheet. Now, no matter the page, the browser will look in the same place.
(If this works for you, please make sure you check the checkmark to accept the answer. And then go back and accept the working answers from your previous questions!)