CodeIgniter Forums
Session checking & loading a new view depending on the result - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Session checking & loading a new view depending on the result (/thread-11185.html)



Session checking & loading a new view depending on the result - El Forum - 08-29-2008

[eluser]Joseph1982[/eluser]
Hello All,

I am new to CI and now working with Session Management. I have to check the save the data in the Session and load a new view after successful login. Yesterday I completed the login checking & session storing tasks.

After login, the left menu which shows the 'Login Box' need to be replaced with a Welcome Message and a logout link. So how can I accomplish this?

How can I call a same function which displays this Welcome Message from within all classes ?

I am waiting here to hear from you all..

Thank You,
Php Developer.


Session checking & loading a new view depending on the result - El Forum - 08-29-2008

[eluser]Thorpe Obazee[/eluser]
I don't know if I understand your question but if you want the 'sidebar' to be replaced, you can load another view there like this.

sidebar.php
Code:
<div id="sidebar">
You are logged in
<a href="#">logout</a>
</div>
content.php
Code:
&lt;?php $this->load->view('sidebar');?&gt;
<div id="content">
Welcome to the Dashboard
</div>



Session checking & loading a new view depending on the result - El Forum - 08-29-2008

[eluser]Joseph1982[/eluser]
Thank your for your reply..


Session checking & loading a new view depending on the result - El Forum - 08-29-2008

[eluser]Thorpe Obazee[/eluser]
do you want to check if the session is present then shows the 'welcome' message if the session is present but show a login form if not?

I usually do a conditional statement like this:

Code:
// check the session
if ($this->pinoytech_auth->check()) {
// if session is present, then go to dashboard.
    redirect('front/index');
}



Session checking & loading a new view depending on the result - El Forum - 08-29-2008

[eluser]Bramme[/eluser]
You could do something like this in your controller.

Code:
if($this->session->userdata('login') == TRUE) {
    $data['sidebar'] = $this->load->view('welcome', '', TRUE);
} else {
    $data['sidebar'] = $this->load->view('login', '', TRUE);
}
$this->load->view('page', $data);
Then just echo $sidebar in your view where you want your login form OR welcome message.


Session checking & loading a new view depending on the result - El Forum - 09-16-2008

[eluser]Joseph1982[/eluser]
Thank you for your replies...