1

I have a feeling there is a really obvious solution to this but I'm just not seeing it. I'm building a website with codeigniter.

In my views directory I have two folders: template & auth.

I'm trying to include the header from the template directory into a php file in the auth directory.

I'm including it at the top, as always with include '../template/header.php;'

But I'm getting the error:

Message: include(../template/header.php): failed to open stream: No such file or directory

Filename: auth/login.php

Community
  • 1
  • 1
styke
  • 2,116
  • 2
  • 23
  • 51

1 Answers1

3

To include any file in CodeIgniter you should do this :

$this->load->view('template/header');

You can read more about including file in CodeIgniter here :

how to include a file inside a model in codeigniter?

Community
  • 1
  • 1
Dead Man
  • 2,880
  • 23
  • 37
  • Fair does, but why not simply include the header from the view? – styke Apr 01 '13 at 13:47
  • 1
    @styke, why not use the framework the way it was intended to be used? – Mischa Apr 01 '13 at 14:14
  • @Mischa I have no problem with that, it's just I don't feel comfortable editing the auth controller's code and adding my template like this... it seems messy. I'm still going ahead with it. – styke Apr 01 '13 at 14:28
  • @styke - Huh? Controller? You should add that in the view. – Mischa Apr 01 '13 at 14:29
  • @Mischa As far as I know you can't call the function from the view...? I'm trying it now and it doesn't work. – styke Apr 01 '13 at 14:32
  • @styke - You *can* call it in the view. I do it all the time. How are you trying to call it and what error do you get? – Mischa Apr 01 '13 at 14:33
  • @Mischa my bad, had a massive brain-fart. Thanks for your help, I'll be using this method from now on. – styke Apr 01 '13 at 14:39
  • Any time you use `include()`, `require()` or similar in CodeIgniter, the current working directory will be wherever the `index.php` file is, since that is where the request currently is. Your relative path was incorrect because of that. Similarly, CI has very useful constants such as `APPPATH`, and `VIEWPATH` in 3.0, for specifying certain directories. – Aken Roberts Apr 01 '13 at 22:10