CodeIgniter Forums
Including one controller into a main controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Including one controller into a main controller (/showthread.php?tid=27539)



Including one controller into a main controller - El Forum - 02-13-2010

[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'>&lt;?=$menu;?&gt;</div>
            <div id='content'>[b]&lt;?=$content;?[/b]></div>
        </div>

                <div id='footer'></div>

    </div>
    
&lt;/body&gt;
&lt;/html&gt;

And here is my "Main" controller, which is autoloaded when visiting the site:
Code:
&lt;?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;
        
    }

}
?&gt;

And maybe for some clarity here is my menu view:

Code:
&lt;?php foreach($menu_info as $info => $link): ?&gt;
    <div class='menu-header'>&lt;?=$info;?&gt;</div>
    <div class='menu-links'>
    &lt;?php foreach($link as $name => $link): ?&gt;
    <div class='menu-link'>&lt;?=anchor($link, $name);?&gt;</div>
    &lt;?php endforeach; ?&gt;
    </div>
&lt;?php endforeach; ?&gt;
<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


Including one controller into a main controller - El Forum - 02-14-2010

[eluser]Haskabab[/eluser]
No replies at all?