Welcome Guest, Not a member yet? Register   Sign In
CSS not load at somecontroller/somefunction/someid
#1

[eluser]Keem1[/eluser]
I've just started using CI but have a problem.
If I load a page like this: index.php/something/ the CSS files load well, but type index.php/something/other/ the CSS files not load.
How can I tell to CI, the main directory is where index.php is stored? Or anything else to solve this problem?

I'm very-very new, but I want to learn all CI practices.

Oh, before I forget, an other question.
My new website's views load a constant view as header. Is there any chance to load once after initializing, instead of load in each views?

Ps: Sorry for my English, I'm Hungarian :-)
#2

[eluser]CroNiX[/eluser]
Not sure about your css issue, but as far as your 2nd question, here's what I do: I create a helper function that has 2 parameters (title and main content). I have several views that get populated for each page and only the content portion changes.
Library that I autoload containing functions:
Code:
//helper function to generate a main page with the passed in title and content.
    function make_page($title = '', $content = array())
    {
        $data = array();
        $user_info = array();
                
        $user_info['username'] = $this->CI->dx_auth->get_username();
           $user_info['role'] = $this->CI->dx_auth->get_role_name();
         $user_info['last_activity'] = date('M. j, Y g:i a', $this->CI->session->userdata['last_activity']);
           $data['app_version'] = APPVERSION;
           $data['db_version'] = DBVERSION;
         $data['user_info'] = $this->CI->load->view('userinfo', $user_info, TRUE);
         $data['menu'] = $this->CI->load->view('menu', $user_info, TRUE);
           $data['page_title'] = $title;
           $data['content'] = $content;    
         //this is my main template which the other views are passed into
         $this->CI->load->view('template', $data);
    }

Then I just have to:
Code:
$this->global->make_page('Title of this page', $this->load->view('somedir/someview', $data, TRUE));
where the view being loaded in there is my 'content'.
#3

[eluser]pistolPete[/eluser]
[quote author="Keem1" date="1236122788"]If I load a page like this: index.php/something/ the CSS files load well, but type index.php/something/other/ the CSS files not load.
How can I tell to CI, the main directory is where index.php is stored? Or anything else to solve this problem?[/quote]

Are you using relative paths in your views?
Please post your view code.
#4

[eluser]Keem1[/eluser]
[quote author="pistolPete" date="1236125730"]Are you using relative paths in your views?
Please post your view code.[/quote]

Yes, relative because I'll use the same site on localhost and web server.

Here's my header_view.php file. The "style" folder is in the same folder where the system and index.php.
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;meta http-equiv="content-type" content="text/html; charset=iso-8859-2" /&gt;
        &lt;meta name="author" content="Keem1" /&gt;
        &lt;title&gt;&lt;?php print $title; ?&gt;&lt;/title&gt;
        &lt;link href="style/mainstyle.css" rel="stylesheet" type="text/css" /&gt;
[removed]
&lt;/head&gt;
&lt;body&gt;

CroNiX: I'm going to try your code, thanks!
#5

[eluser]pistolPete[/eluser]
[quote author="Keem1" date="1236126435"]Yes, relative because I'll use the same site on localhost and web server.[/quote]
You can use absolute paths without specifying the domain / server adress.
Add a forward slash at the beginning of the path:
Code:
&lt;link href="/style/mainstyle.css" rel="stylesheet" type="text/css" /&gt;
This only works if the folder style is in the root directory:
http://<<host>>/style/
You have to adjust the path above if it's different!
#6

[eluser]Keem1[/eluser]
[quote author="pistolPete" date="1236128175"]
You can use absolute paths without specifying the domain / server adress.
Add a forward slash at the beginning of the path:
Code:
&lt;link href="/style/mainstyle.css" rel="stylesheet" type="text/css" /&gt;
This only works if the folder style is in the root directory:
http://<<host>>/style/
You have to adjust the path above if it's different![/quote]

Oh, my god... it works! How did this not occur to me?
Thank you!
#7

[eluser]xwero[/eluser]
a function to show how the server sees the relative path




Theme © iAndrew 2016 - Forum software by © MyBB