i have a problem including a folder/file in codeigniter, this is how the files are structured in my view.
-application
-model
-controller
-view
-auth
-login.php //I want to include header.php, sidebar and footer on this file
-includes
-header.php
-sidebar.php
-footer.php
on the application/view/auth/login.php i have include('../../include/header'); but is not working, i have tried several other means and no job also i cant use an absolute path because the files are in the application folder.
edit:
example in my view folder i have index.php file and i has the following codes
<?php
include('includes/header.php');
include('includes/sidebar.php');
?>
<div id='content'>
<h3>Title</h3>
<p>contents contents</p>
</div>
<?php include('/includes/footer.php'); ?>
Now in the view folder is another folder called auth and i have a file in it called login.php and has the following codes
<?php include(../includes/header.php);?> //this doesn't work
<?php include(../includes/sidebar.php);?> //this doesn't work
<div id='form'>
<form>
</form>
</div>
<?php include(../includes/header);?> //this doesn't work
on my controller i have
<?php
class Index extents CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('index'); //this works and loads all the includes
}
}
another example of a controller not working
<?php
class Login extents CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('auth/login'); //this works but doesn't load the includes
//in the login.php file found inside the auth
//folder
}
}
Take a look a the view loader (http://ellislab.com/codeigniter/user-guide/libraries/loader.html).
Most CI functions are available with inviews, so you can use something like this:
Instead of
include('../../include/header');
use
$this->load->view('includes/header');
This is an old post, but for as many as would stumble upon it.
I'll advice that you move the include folder to your root folder. It shouldn't be in the application folder, but the folder where the application folder is.
Then you replace with
<?php include(base_url(include/header.php)); ?>
That should do the trick.