Welcome Guest, Not a member yet? Register   Sign In
Calling controller within view?
#1

[eluser]Unknown[/eluser]
Hey there! I'm brand new to using a framework, but found CI today and I'm loving it so far. It seems to make development a whole lot easier.

I ran into a problem, though. At the top of each page I'm loading my "header" view. This contains my top title and links, etc. I realized I want to have a little control panel on the right side (within this view) that will either display the login form if they're a guest, or options to mess with their account (if they're logged in).

I'm not sure how to go about this. I want to simply call the control panel controller (within the view) and that's it. Otherwise, I have to split apart the views and process it on every single controller (in the constructor maybe).

Any thoughts on the best way to handle this?
-Jason
#2

[eluser]Cristian Gilè[/eluser]
Load a different view for different users. In the controller check if a user is loggedin or not:

Code:
if($this->auth_lib->is_logged_in())
{
   $data['panel'] = $this->load->view('user_panel','',TRUE);
}
else
{
   $data['panel'] = $this->load->view('guest_panel','',TRUE);
}

$data['content'] = $this->load->view('body_view','',TRUE);

$this->load->view('template',$data);



You can use a master template view like this:

template view:

Code:
$this->load->view('header');

echo $content;
echo $panel;

$this->load->view('footer');

There are different solutions. Take a look at this template lib


Cristian Gilè




Theme © iAndrew 2016 - Forum software by © MyBB