0

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?

1
  • Why you did that way? Why calling another method just to load a view rather than load the view directly from it (in fact your conditional statement will return the same result, after all). I just confuse, why you did that? Commented Aug 12, 2011 at 11:48

3 Answers 3

1

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

<link rel="stylesheet" type="text/css" href="style.css" />

This will only work if the path stays the same. However, your path is changing from /controller2 to /controller2/test, which means on the second page, the browser is going to look for /controller2/style.css for the first method, and /controller2/test/style.css for the second.

Correct

<link rel="stylesheet" type="text/css" href="<?php echo site_url('style.css') ?>" />

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!)

Sign up to request clarification or add additional context in comments.

Comments

0

ya, site_url() working for css as well as javascript linking

Comments

0

Try this:

<link rel="stylesheet" type="text/css" href="<?php echo site_url()?>style.css" />

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.