Welcome Guest, Not a member yet? Register   Sign In
index.php - works - index.php/home - does not - Please help explain
#1

[eluser]ICEcoffee[/eluser]
Hi Folks

I have on my local server a directory called ci2. I have setup a default controller called home.php. I have in my config file:

Code:
$config['base_url'] = "http://127.0.0.1/ci2/";
$config['index_page'] = "index.php";

My default controller (home) is this:
Code:
<?php
class Home extends Controller
{
    public $data;
    
    public function _Constructor()
    {
        // initiators
        parent::Controller();
    }
    
    public function index()
    {
        // get data from database
            
        $data['name'] = "brian" ;
        $this->load->view('home_view', $data);
    }
    
}

My View file mentions in the above code is this (head section only):
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html&gt;
    &lt;head&gt;
       &lt;title&gt;&lt;? echo $meta_title; ?&gt;&lt;/title&gt;
         &lt;? echo $config['style_main']; ?&gt;
         &lt;link rel='stylesheet' href='styles/style.css' type='text/css' media='screen' charset='utf-8' /&gt;
         &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
        &lt;link rel="shortcut icon" href="../favicon.ico" /&gt;
    &lt;/head&gt;

The problem?
if I type into my browser: http://localhost/ci2/
or http://localhost/ci2/index.php, I see the referenced stylesheet.

If I type: http://localhost/ci2/index.php/home/ I DO NOT SEE THE STYLESHEET.

Can someone explain what is happening.

Thank you.
#2

[eluser]stuffradio[/eluser]
I'm not too sure right now, but you have a space after $data['name'] = "brian" ;

Try removing that.
#3

[eluser]Merolen[/eluser]
Doesn't the base_url have to be there? I you don't specify it it is relative to the URL you see in your URL field.

Code:
&lt;link rel='stylesheet' href="&lt;?=base_url()?&gt;styles/style.css" type='text/css' media='screen' charset='utf-8' /&gt;
#4

[eluser]Brandon Dickson[/eluser]
Merolen's correct, CI uses url routing to make things cleaner, but to your web browser, when you type in:

http://localhost/ci2/index.php/home/

the browser assumes that "home" is a directory, so its looking for you css file here:

http://localhost/ci2/index.php/home/styles/style.css

try using site_url('styles/style.css') or base_url() as Merolen described.

-Brandon
#5

[eluser]ICEcoffee[/eluser]
The previous two posts sounds 'bang on the money'. It's seems the 'logical' action to use. I don't know why I didn't think of it. :red:

Thanks guys, I'll give that a go later.




Theme © iAndrew 2016 - Forum software by © MyBB