[eluser]Haskabab[/eluser]
Hello guys,
I've previously started a topic on how to create a template system. And it really helped me with creating a main template and dividing it into different views and load them all into each other etc.
Now i've encountered a problem which i'm pretty sure is unfixable, by doing it my way. So i think that i'm searching in the wrong direction here so i hope someone can help me with it.
What i've got so far is a main template view looking like this: (stripped code, just for showing you guys what i mean.
Code:
<html>
<body>
<div id='wrapper'>
<div id='banner'></div>
<div id='container'>
<div id='menu-container'><?=$menu;?></div>
<div id='content'>[b]<?=$content;?[/b]></div>
</div>
<div id='footer'></div>
</div>
</body>
</html>
And here is my "Main" controller, which is autoloaded when visiting the site:
Code:
<?php
class Main extends My_Controller {
function Main(){
parent::My_Controller();
}
function index(){
$data = array();
$data['menu_info'] = $this->_generateMenu();
$data['menu'] = $this->load->view('menu_view', $data, TRUE);
$this->load->view('templates/master_template', $data);
}
function _generateMenu(){
$menu_data_array = array(
"Main Menu" => array(
"Home" => "index.php",
"About" => "about"
),
"User Options" => array(
"Hoi" => "hoi",
"Hai" => "blub"
)
);
return $menu_data_array;
}
}
?>
And maybe for some clarity here is my menu view:
Code:
<?php foreach($menu_info as $info => $link): ?>
<div class='menu-header'><?=$info;?></div>
<div class='menu-links'>
<?php foreach($link as $name => $link): ?>
<div class='menu-link'><?=anchor($link, $name);?></div>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
<div class='menu-footer'></div>
But now!. My main question is: How can i autoload a controller into my main template if no uri is present, and if there is, how to load that controller before the page renders.
I though that i should write some code in my main controller since that is where the master template is loaded but i dont know how i should do that. And any other way i thought about turned out to be complete nonsense...
So maybe someone knows how to do it.
Btw, i'm using a MY_Controller, which is:
Code:
class MY_Controller extends Controller {
function MY_Controller(){
parent::Controller();
}
function index(){
}
}
Pretty much empty!
So yeah, if anyone has some feedback? Thanks in advance.
~Nick