Cannot include files - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Cannot include files (/showthread.php?tid=18603) |
Cannot include files - El Forum - 05-12-2009 [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'); 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? Cannot include files - El Forum - 05-12-2009 [eluser]Dam1an[/eluser] Why not just use the loader? Code: $this->load->view('html/header'); Cannot include files - El Forum - 05-12-2009 [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" /> Cannot include files - El Forum - 05-12-2009 [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" /> Cannot include files - El Forum - 05-12-2009 [eluser]porta_ss[/eluser] Thanks a lot for the advice Cannot include files - El Forum - 05-13-2009 [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! Cannot include files - El Forum - 05-13-2009 [eluser]porta_ss[/eluser] It works, thanks a lot!!! |