Welcome Guest, Not a member yet? Register   Sign In
Odd issue - stylesheet being ignored sometimes
#1

[eluser]ZeroLag[/eluser]
Forgive me if this doesn't turn out to be 100% CI related.

My stylesheet is being ignored on all pages except for the main page in my application.
I am calling a template from my controllers that basically sets the page layout and takes content as a variable sent from the controller as well.

View template:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Title Here&lt;/title&gt;
&lt;meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'&gt;
&lt;link href="public/admin/css/admin_style.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;
&lt;body bgcolor='#E2E1E1'&gt;
<div id='container'>
<div id='searchwindow'>
    <div class='colheader'>Search</div>
    <div style='padding: 2px;'>
            &lt;form name='searchform' action='quicksearch.php' method='GET'&gt;
                &lt;input type='text' name='searchstring' value="&lt;?= $string ?&gt;"&gt;
                &lt;input type='submit' value='Search'&gt;
            &lt;/form&gt;        
    </div>
</div>
    <div id='contentwindow'>
        &lt;!-- Content --&gt;
        &lt;? echo $content; ?&gt;
        &lt;!-- End Content --&gt;
    <div>  
</div> &lt;!-- end container --&gt;
&lt;/body&gt;
&lt;/html&gt;

The function calling this view looks like this:
Code:
&lt;?php
class Home extends Controller {
    
    function Home()
    {
         parent::Controller();
        
         //Protects account controller
         $this->freakauth_light->check('admin');

        //Loads the model and database for this whole controller
        $this->load->model('candidates');
        $this->load->model('contacts');
        $this->load->model('clients');
        $this->load->database();
        $this->load->helper(array('html_date_select', 'proficiency', 'child_age'));
                
        //Enable profiling on this controller?
        //$this->output->enable_profiler(true);
    }
    
    function index()
    {
        $this->view();
    }
    
    function view()
    {
        $data['username'] = $this->db_session->userdata('user_name');
        $data['string']   = "test";
        
        //Get the lists of all the recently added records
        $data['newestCandidates'] = $this->candidates->getRecentlyAddedCandidates();
        $data['newestContacts']   = $this->contacts->getRecentlyAddedContacts();
        $data['newestClients']    = $this->clients->getRecentlyAddedClients();
        
        //Get the lists of all the most recently modified records
        $data['recentlyUpdatedCandidates'] = $this->candidates->getRecentlyUpdatedCandidates();
        $data['recentlyUpdatedContacts']   = $this->contacts->getRecentlyUpdatedContacts();
        $data['recentlyUpdatedClients']    = $this->clients->getRecentlyUpdatedClients();
        
        //Get the list of most recently uploaded files
        $data['recentlyUploadedFiles'] = $this->candidates->getRecentlyUploadedFiles();
        
        //Load the view
        $data['content'] = $this->load->view('admin/home', $data, true);
        $this->load->view('admin/shared/main_template', $data);
        
    }
}
?&gt;

In any other controller I use, even if I simply copy/paste the view function the template is called and the page will load, but the stylesheet information is completely ignored. I know this is the case because if I comment out the &lt;link rel="stylesheet"&gt; tag and reload my "correctly working" controller, it looks just like all the controllers that don't work.

I don't really understand how this is possible. They all call the exact same view, and I have confirmed that everything is exactly the same by looking at the page sources in my browser. All I can conclude is that the CSS is being ignored on all pages except one.

Can anyone help?
Thanks,
Steve
#2

[eluser]Flemming[/eluser]
First thing to do is make sure the path to the stylesheet is correct.

I would make the path from the root (forward slash at beginning):

Code:
&lt;link href="/public/admin/css/admin_style.css" rel="stylesheet" type="text/css"&gt;
#3

[eluser]ZeroLag[/eluser]
That was it. I don't understand exactly why that fixes the issue. Both controllers were in the same folder, and even still, aren't the paths relative to the index.php file in the root?

In any event, it was an easy fix; thanks for the help!

Steve
#4

[eluser]khagendra[/eluser]
Give the absolute path. The problem will be solved.

Try this

Code:
&lt;link href="&lt;?=base_url()?&gt;public/admin/css/admin_style.css" rel="stylesheet" type="text/css"&gt;

Note: Use the trailing slash(/) in the base_url in the config/config.php file

Code:
$config['base_url'] = "http://example.com/";

OR
Code:
$config['base_url'] = "http://localhost/folderName/";
#5

[eluser]John_Betong[/eluser]
&nbsp;
Give this a try:

Set this config parameter and it should work for both LocalHost and OnLine withut any changes.
Code:
// config.php
  $config['base_url']    = 'http://' .$_SERVER['SERVER_NAME'] .'/';
&nbsp;
&nbsp;
&nbsp;
#6

[eluser]jedd[/eluser]
Or, since you want something safe, concise, portable and CI:

Code:
echo "\n". link_tag('public/admin/css/admin_style.css');
#7

[eluser]Aken[/eluser]
[quote author="ZeroLag" date="1259217105"]That was it. I don't understand exactly why that fixes the issue. Both controllers were in the same folder, and even still, aren't the paths relative to the index.php file in the root?

In any event, it was an easy fix; thanks for the help!

Steve[/quote]
Think of it like an image's source location. It's not the server-side PHP script checking the location of that CSS file, it's the user-side HTML page looking for it. An HTML page thinks its location is what is in the web bar, and it will look for files relative to that location.




Theme © iAndrew 2016 - Forum software by © MyBB