Welcome Guest, Not a member yet? Register   Sign In
Home method not working the same as default setting
#1

[eluser]kkathman[/eluser]
I have a home controller with two methods, index() and aboutus(). I placed my css and includes directory at the same level as the applications folder, which is outside my system folder.

SO:

htdocs
..oi
....application (controllers/models/views etc)
....css
....includes
....index.php
....system

When I go to my browser and type in:

http://localhost/oi/

The home screen comes up fine with everything looking good. The code and css render the page great.

When I go to my browser and type in:

http://localhost/oi/index.php

The home screen comes up fine and renders fine.

HOWEVER,

When I go to my browser and type in:

http://localhost/oi/index.php/home or
http://localhost/oi/index.php/home/index

There is no CSS rendering at all.


In my config.php I have the default:

$config['base_url'] = "http://localhost/oi/";

In my routes.php I have the default:

$route['default_controller'] = "home";


So my questions are:

1) Why don't they render the same?
2) How do you set things so that all of these render properly regardless of the invocation?


Thank you for your help!
#2

[eluser]mi6crazyheart[/eluser]
Are u getting any error ? Plz, get conform also path of CSS file which u r using in u'r VIEW file(from controller HOME).....
#3

[eluser]Dennis Rasmussen[/eluser]
Use base_url() when linking to your CSS files.
#4

[eluser]kkathman[/eluser]
As a follow up to this, I'm just trying to determine best practice.

Let's say I have 2 pages...home page and contact.

I created my home page as a home.php controller, and a home_view.php view.
I created my contact page as a contact.php controller, and a contact_view.php view.

my base url = http://localhost/oi/

I am autoloading the URL helper.
Routes default controller is "home".

The "css" directory is at the same level in my root as System.

In the home view I use the following link to the css:
<link rel="stylesheet" type="text/css" media="all" href="css/style.css" />

This works fine IF and ONLY IF I launch the site in the browser by typing: http://localhost/oi/

However, if I launch as http://localhost/oi/index.php/home the css file is not found, and doesnt render. I must aler the link to the css in the view to "../css/style.css" because it's calling at a deeper level.

This is quite confusing I think, especially when loading to a hosting site.

So am I to just assume that the routes (for default controller) really doesn't mean anything and that when loading to a site you should just link to the full path of http://localhost/oi/index.php/home ?

Again, I'm just looking for what's best practice.

Thanks,
Korky
#5

[eluser]InsiteFX[/eluser]
As Dennis Rasmussen mentioned above:
Code:
<link rel="stylesheet" type="text/css" media="all" href="<?php echo base_url();?>css/style.css" />

You will need to include this in all your views or just place in a
header view and load that.

InsiteFX
#6

[eluser]techgnome[/eluser]
Quote:So am I to just assume that the routes (for default controller) really doesn’t mean anything and that when loading to a site you should just link to the full path of http://localhost/oi/index.php/home ?
Sometimes "best practice" and "what works" are two different things. In this case, the recommendation and what works is to use a full url. If it's in your root, you might be able to reference it relative to the root. Currently you're referencing it relative to the view location.

-tg




Theme © iAndrew 2016 - Forum software by © MyBB