Welcome Guest, Not a member yet? Register   Sign In
Including files in Views
#1

[eluser]Unknown[/eluser]
Hi there, I've recently begun setting up a website in Code Igniter and have run into a little problem concerning structure/page setup...

My problem is that in the Views folder I have a sub-folder called "constants" which holds files such as header.php, navigation.php etc. I also have a number of other sub-folders within the Views folder that hold specific Views pages based on sections of the website. So in essence, my Views folder looks like this:

main_view.php
constants
|-header.php
|-footer.php
|-nav.php
about_view.php
some_folder
|-some_file.php

My problem now comes when I try and link a file from the constants folder (i.e. header.php) into the "some_file.php" file.

Code:
<?php require_once('../constants/header.php'); ?>
// This does not work for some reason, and after trying a few other options, I'm stumped!

Any suggestions would be of great help.

Thanks a million in advance,
Matt
#2

[eluser]Craig A Rodway[/eluser]
Instead of include(), the preferred method is to use:

Code:
<?php $this->load->view('constants/header'); ?>

Even in your views Smile
#3

[eluser]Unknown[/eluser]
Of course! I don't know why I didn't try that before!

Looks like I'm still stuck in procedural coding practices... I have a fair way to go with getting fully to grips with this framework (and method of development) but I'll get there in the end no doubt!

Thank you so much Craig,
Matt




Theme © iAndrew 2016 - Forum software by © MyBB