0

I've just started a Codeigniter project and I'm facing issues in linking the header and footer files to a page inside the view's subfolder. My directory structure is

  • Application
    • Views
      • includes
        • header.php
        • footer.php
      • details
        • details-page.php
      • index.php
  • System
  • Assets

Linking the header and footer to details-page.php using require_once returns

"failed to open stream: No such file or directory" error.

It works when I use $this->load->view('includes/header'); to link the files but shows the error when using require_once('../includes/header.php');

Nate Barbettini
  • 51,256
  • 26
  • 134
  • 147
  • what do you have in index.php? my main index.php is in root and it holds paths, etc. Maybe issue is in paths? – Angel M. Aug 23 '15 at 18:00

1 Answers1

0

The correct way using CI is to load the view in your controller.

 $this->load->view("file-in-views-folder");

However, if you want to use require_once statement then you should use CodeIgniter's built in constant APPPATH . Like this

require_once(APPPATH.'views/includes/header.php');
Suvash sarker
  • 3,140
  • 1
  • 18
  • 21
  • Hi. Thanks for your quick reply.. Is $this->load->view("file-in-views-folder"); works as same as require_once? Since there are many file linking types like include,include_once and require...$this->load->view("file-in-views-folder"); is an alternate for which type in CI? – design advisor Aug 24 '15 at 17:57
  • You can take look here http://stackoverflow.com/questions/3675135/codeigniter-best-way-to-structure-partial-views and http://www.amitavroy.com/justread/content/articles/part-2-creating-partial-views-and-loading-them-inside-container-view I think this will help you. – Suvash sarker Aug 25 '15 at 17:12