CodeIgniter Forums
Problem with Organizing Views in Folders - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Problem with Organizing Views in Folders (/thread-24269.html)



Problem with Organizing Views in Folders - El Forum - 11-04-2009

[eluser]CARP[/eluser]
Hi guys
I'm having a little problem trying to organize views in subfolders.
I've created (and divided) the views in:

views/inc_header.php
views/inc_footer.php

Then I've a view file stored in
views/parameters/city

And in the view file, I have:
Code:
<?
include("../inc_header.php");
?>

but I'm getting the following

Severity: Warning
Message: include(../inc_cabecera.php) [function.include]: failed to open stream: No such file or directory
Filename: parameters/city.php
Line Number: 2


Thanks a lot in advance for any tip you can give me


Problem with Organizing Views in Folders - El Forum - 11-04-2009

[eluser]n0xie[/eluser]
Code:
<?php
$this->load->view('inc_header');
?>



Problem with Organizing Views in Folders - El Forum - 11-04-2009

[eluser]CARP[/eluser]
[quote author="n0xie" date="1257399141"]
Code:
<?php
$this->load->view('inc_header');
?>
[/quote]

worked great!, but got another problem
In the file views/inc_header.php I had the following:

Code:
$dir_views = $this->config->item('dir_views');

and I can't use or reference to $dir_views in the file: views/parameters/city.php (I get an error). I've fixed this temporarily by copying the above line of code to each view...

Smile


Problem with Organizing Views in Folders - El Forum - 11-04-2009

[eluser]Jamie Rumbelow[/eluser]
You can pass through any variables to any of the views you load by passing through an array of keys as variable names and values as the variable value as the second parameter to the $this->load->view() function. For instance, if you wanted to pass through the $dir_views variable to the parameters/city.php view:

Code:
$dir_views = $this->config->item('dir_views');

$data = array(
    'dir_views' => $dir_views
);
$this->load->view('parameters/city', $data);



Problem with Organizing Views in Folders - El Forum - 11-05-2009

[eluser]CARP[/eluser]
That's a better way Jamie
Thanks to Everyone