Welcome Guest, Not a member yet? Register   Sign In
Calling multiple Views...
#1

[eluser]Harvard725[/eluser]
Obviously I'm new to CI...

I'm feeling pretty stupid right now because the simplest of simple things isn't working for me... Is there any reason why I keep getting an error message when I attempt to load more than one view from one controller? Am I not supposed to be loading two views at once?

class Main extends Controller {

function index()
{
$this->load->helper('url');
$this->load->view('header_view');
$this->load->view('main_view');
$this->load->view('footer_view');
}

}



I keep getting the message...

An Error Was Encountered
Unable to load the requested file: header_view.php



That doesn't make any sense, does it?
#2

[eluser]pilotLight_Tre[/eluser]
You are looking for the Layout Library: http://codeigniter.com/wiki/layout_library/

It does exactly what you are looking to do. Instead of a separate header and footer view file, you will only need one main view file to display both the header and footer.

This is how you would use it:

Code:
class Demo extends Controller
{
function __construct()
{
parent::Controller();

$this->load->library('library');

$this->layout->setLayout('location/of/main_layout');
}

function index()
{
$templatedata['title'] = 'Hello world';

$this->layout->view('location/of/main_view', $template_data);
}

}
#3

[eluser]TheFuzzy0ne[/eluser]
If the file can't be loaded it's due to one of two things.
1) The files permissions are incorrect, or
2) The file really doesn't exist.

In my experience, it's usually the latter.
With the load view calls you have, you'll need the following three files in your views directory:

header_view.php
main_view.php
footer_view.php
#4

[eluser]Harvard725[/eluser]
Yeah. I'm thoroughly embarassed now. CodeIgniter is brilliant, yet humbling. It's been a frustrating day. I had the files in a different folder. Thanks for your reply Fuzzy.
#5

[eluser]TheFuzzy0ne[/eluser]
Everybody makes mistakes, even more so when they're learning. I wish you every success with CodeIgniter. Stick with it, and I promise you won't regret it.

All the best!




Theme © iAndrew 2016 - Forum software by © MyBB