Welcome Guest, Not a member yet? Register   Sign In
problem with accessing model from view...
#1

[eluser]jacobson[/eluser]
Hello I have a problem. On my site I use template and in the header I include the "login bar" to appear on each site. I want to access the model in order to get an information about logged user but I have no idea how to do that because I don't use any controller (because the login bar is default). In my opinion the only way is to access the model from my view file to get the informations and to process them to show what I want. Am I right ? because it somehow breaks the MVC.
#2

[eluser]cahva[/eluser]
Use the MY_Controller method and set the login bar in that base controller.

Theres a great article how to setup base controller(s) and it can be found here:
http://philsturgeon.co.uk/blog/2010/02/C...ing-it-DRY
#3

[eluser]jacobson[/eluser]
you mean to add another variable which will be passed to the view, which will load the login bar ?

I've tried to create MY_Controller

Code:
class MY_Controller extends CI_Controller {

    function __construct() {
        parent::__construct();
    }
    
    function show_login_bar(){
        $data['login_bar'] = 'includes/login_bar.php';
        $this->load->view('includes/template', $data);
    }

}

I dunno if it's ok.. but when I try to extend my controllers to MY_Controller, nothings appears, no site
"Remote server or file not found"

OK, I found the problem with this MY_Controller, I just put it into libraries instead the core folder. But anyway, anyone could tell me how to load "another view".
For now I have in all controllers the $data['main_content'] which I use to "choose" which site to load and in my template I just load the $main_content to which the proper view is assigned. But have no idea how to do this with the login bar in this MY_Controller.




Theme © iAndrew 2016 - Forum software by © MyBB