Welcome Guest, Not a member yet? Register   Sign In
Load in controller or view?
#1

[eluser]überfuzz[/eluser]
I have several small view file as parts of the main frame. Example of how the views are loaded in one of the view files:
Code:
<? $this->load->view('html_head'); ?>
<? $this->load->view('header'); ?>
<? $this->load->view('menu'); ?>
What I would like to know is if there are any benefits or down sides if I load the view files in the controller, like this:
Code:
$this->load->view('html_head', $this->data);
$this->load->view('header', $this->data);
$this->load->view('menu', $this->data);
Or is there an even nicer way of doing this view loading? I'd like to move the loading to the controller, but then the designer feels that it hard to tell whats going on... Undecided
#2

[eluser]NateL[/eluser]
Chances are you will be writing a lot of methods, and to type in the same 3-5 lines in every method just to get the header, menu, sidebar, footer, and content to show up just doesn't make sense.

One way to handle this is to create a view, we'll call it template.php:
You can load views within views...
Code:
<?php
$this->load->view('header');
$this->load->view('menu');
$this->load->view('sidebar');

echo $content;

$this->load->view('footer');

In your controller, you would only have to call that view once, and pass the content variable to it:

Code:
$data['content'] = 'woohoo content goes here!!';
$this->load->view('template', $data);
#3

[eluser]bretticus[/eluser]
For a slightly different approach to Nate's, watch this video from Nettuts. It's the same thing except the template view loads the content view dynamically (so you can still have individual views that make up the content area.) Just make sure that the variable that gets passed to the template view cannot be injected or this method could possibly be a little bit insecure.
#4

[eluser]überfuzz[/eluser]
@Nate - Thats exactly how I'm doing it now, didn't knew it was called template system. I'll stick to it.

@bretticus - Gezz louise, hes addressing a lot of stuff in his video. Tnx for the link!
#5

[eluser]NateL[/eluser]
tehehe....I admit I was turned onto this method by watching that nettuts video. My last 2 or 3 posts have had a link to that video.........i think i'm going to put some links in my sig for that series...it rocks...truly.
#6

[eluser]InsiteFX[/eluser]
Ya I am waiting for day7

Enjoy
InsiteFX
#7

[eluser]bretticus[/eluser]
[quote author="überfuzz" date="1253095061
@bretticus - Gezz louise, hes addressing a lot of stuff in his video. Tnx for the link![/quote]

Ha, yeah after posting I thought, "I should have given him the time to fast forward to."




Theme © iAndrew 2016 - Forum software by © MyBB