[eluser]Armorfist[/eluser]
I'm building my CMS with CI and I'm trying to figure the best way to organize my views so that i dont repeat load->view every time i want to load the backend header for example. This is how I'm doing it:
For example, under the module "users" in the "application/modules/users/controllers/admin" directory, i have a controller named "admin" that has the following code:
Code:
<?php
class Admin extends Controller {
function Admin ()
{
parent::Controller();
}
function index()
{
$user_check = $this->db->query('SELECT * FROM login_users');
$teste = array(
"teste1" => "value1",
"teste2" => "value2",
"db" => $user_check
);
$data['view_name'] = 'admin/teste';
$data['view_module'] = 'users';
$data['view_data'] = $teste;
$this->load->view('backend/container',$data);
}
}
?>
And under the folder "application/modules/users/views/admin" i have a view named teste.php with the following code:
Code:
Test
<?php
echo $teste1."<br/>";
echo $teste2."<br/>";
foreach ($db->result() as $row)
{
echo $row->username."<br/>";
echo $row->password."<br/>";
echo $row->active."<br/>";
}
?>
Now, under "application/views" i have a folder named "backend", which contains:
header.php - The header html code of the backend
menu.php - The menu of the backend
footer.php - The footer html code of the backend
login.php - The view that contains the login form
Then i have "cointainer.php", the view that loads the "header", "menu" and "footer" view along with the "content" view. The code:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
// If user isn't logued, include login view, else include backend layout views
if ($this->evdcms_login->is_logued)
{
//Load Header
$this->load->view('backend/header');
//Load Menu
$this->load->view('backend/menu');
//Load Content based on $view_name,$view_module variable
$this->load->module_view($view_module,$view_name,$view_data);
//Load Content div end & Footer
$this->load->view('backend/footer');
}
else
{
//Load login form
$this->load->view('backend/login');
}
?>
Am i doing this right? Suggestions will be greatly appreciated.