• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot include files

#1
[eluser]porta_ss[/eluser]
Hello ppl, I'm a newby to CodeIgniter and I got into some kind of a problem. First of all I wrote 2 views, header.php and footer.php...each of them containing some html. I placed these 2 inside views/html/
Inside "views" I also have another folder, called "auth" which contains some other views.
The structure is sth like this:
views/
html/
header.php
footer.php
auth/
fail_view.php

Now, I'm trying to include header.php in fail_view.php like this:
Code:
include_once('../html/header.php');
It sais it can't locate ../html/header.php
I'm a little lost...include() works fine in the same directory and if I accss a directory directly like "html/header.php" but in my example above it doesn't work.
The reason why I'm doing this is cause I don't like calling header and footer views from controllers each time I need them...and although it isn't that much of a difference...it is more confortable to me to include these files.
Same problem happens with my css...I had to write the full url in the src to call the external stylesheet...
what should I do?

#2
[eluser]Dam1an[/eluser]
Why not just use the loader?
Code:
$this->load->view('html/header');

#3
[eluser]porta_ss[/eluser]
Well that worked indeed, thanks a lot...I haven't thought to load a view directly inside of another view...
But what should I do to be able to load propperly the css(which is located in application/assets/) from the views/html/header.php? I mean...without giving the full path?(I can load css using direct urls)
I have tried to access the stylesheet like this:
Code:
<link rel="stylesheet" href="../../assets/styles/style.css" type="text/css" />
but it only works if I give the full url

#4
[eluser]TheFuzzy0ne[/eluser]
If you want something to be directly accessible via the Web, it needs to be somewhere within your Web root. Otherwise you'd need to create a controller or something that will receive the request in your Web root, and output the appropriate stylesheet.

EDIT: Also, you should make your request absolute to the Web root.

Code:
<link rel="stylesheet" href="/../../assets/styles/style.css" type="text/css" />

#5
[eluser]porta_ss[/eluser]
Thanks a lot for the advice

#6
[eluser]Cro_Crx[/eluser]
If you're including the same header on different pages it might be best to use
Code:
href = "<?=base_url()?>assests/styles/style.css"

The reason for this is because website.com and website.com/page will produce different links when using relative paths.
Just make sure you include the URL helper!

#7
[eluser]porta_ss[/eluser]
It works, thanks a lot!!!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.