CodeIgniter Forums
Pass $data array element from MY_Controller to view - 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: Pass $data array element from MY_Controller to view (/showthread.php?tid=26515)



Pass $data array element from MY_Controller to view - El Forum - 01-15-2010

[eluser]Unknown[/eluser]
I'm probaly being a div but I wondered if anyone can recommend a way I can populate a view from MY_Controller.
What I want really is a login form on every page if they're logged. User menu if they're not. Easy probaly.

Code:
class  MY_Controller  extends  Controller  {

    function MY_Controller ()  {
        parent::Controller();
        $this->load->library('tank_auth');
        if (!$this->tank_auth->is_logged_in()) {
            $data['login'] = 'login';
             something here
        } else {
            $data['user_id']    = $this->tank_auth->get_user_id();
            $data['username']    = $this->tank_auth->get_username();
            $data['login'] = 'notifications';
            something here
            
        }

    }
}

and the view file

Code:
<div id = "logo" class = "span-11">
<h1>Logo</h1>
</div>
<div id = "search" class = "span-13 last">
</div>
<div id = "log_in" class = "span-13 last">
<p class = "strong last">&lt;?php $this->load->view($login); ?&gt;</p>
</div>

dont worry sussed it, just used vars.


Pass $data array element from MY_Controller to view - El Forum - 01-16-2010

[eluser]flaky[/eluser]
I'd recommend you to use Template Library
http://www.williamsconcepts.com/ci/codeigniter/libraries/template/

this way you can configure your default regions and which region what to display