Welcome Guest, Not a member yet? Register   Sign In
Question about template
#1

[eluser]Carmichael[/eluser]
Hi. I've four files I want to include in every page.
common/header.php
common/sidebar_left.php
common/sidebar_right.php
common/footer.php

Now I use $this->load>view('common/sidebar_left') to include common/sidebar_left in the header and $this->load>view('common/sidebar_right') to include common/sidebar_right in the footer.

header
Code:
// some shitty stuff here

<div id="left">
&lt;?php echo $this->load->view('commmon/sidebar_left');
</div>

footer
Code:
// some shitty stuff here

<div id="right">
&lt;?php echo $this->load->view('commmon/sidebar_right');
</div>

And then in all controllers I get three view files:

Code:
$this->load->view('common/header');
$this->load->view('controller_view');
$this->load->view('common/footer');

The problem is sidebar_left and sidebar_right don't get data from their controllers. I have one controller where I build widgets to the sidebar's. The content from sidebar_right/left does get included but not the data from the controller that provides sidebar_right/left with data.
#2

[eluser]Samus[/eluser]
You should really be using the template library for something like this.

But what you could do is create a view file called template.

within the template view, you'd include all of these:

$this->load->view('common/header');
$this->load->view('controller_view');
$this->load->view('common/footer');

Then just load template in your controller and pass your $data to it.


$this->load->view('template', $data);
#3

[eluser]Carmichael[/eluser]
That doesn't solve the problem. The view files still needs to get data from it's controllers.
#4

[eluser]Samus[/eluser]
[quote author="Carmichael" date="1333880696"]That doesn't solve the problem. The view files still needs to get data from it's controllers.[/quote]
if you pass the $data array to the template view, they will.
#5

[eluser]InsiteFX[/eluser]
Maybe you should read the CodeIgniter Users Guide on Views, because you sure do not seem to know how to use them!

CodeIgniter Users Guide -Views

#6

[eluser]Carmichael[/eluser]
I just don't understand how I pass data from a controller to a another controller.
It's easy to just load views (header, footer) in a controller but my files has variable data that do not come off when I load the files.
#7

[eluser]InsiteFX[/eluser]
Phil Sturgeon - CodeIgniter Base Classes: Keeping it DRY




Theme © iAndrew 2016 - Forum software by © MyBB