EllisLab text mark
Advanced Search
     
logon_function in __construct
Posted: 23 May 2012 09:50 AM
Joined: 2012-05-18
6 posts

so i have my model where i make a select and if all’s good, userdata() gets set.

$data = array(
                
'is_logged_in' => true,
                
'gebruiker' => $row['gebruikers_naam']
                
);
                 
$this->session->set_userdata($data); 

i wrote a function to check if your logged in or not:

public function is_logged_in(){
        $is_logged_in 
$this->session->userdata('is_logged_in');
        
        if(!isset(
$is_logged_in) || $is_logged_in != true)
        
{   
            $data[
'title'"Intruder !!";
            
$data['views'= array("v_message");
            
$data['message'"No acces mate";
            
$this->load->view('v_template',$data);
        
}else{
            $data 
"";
        

        
return $data;
    

Now in my contruct i do this:

public function __construct() {
        parent
::__construct();
    

now lets say i call a funtion:

public function plaatsbestelling()
    
{  
            $data[
'title'"De bestelling plaaten";       
            
$data['views'= array("v_bestelboninvullen");
            
$data['locaties'$this->maakLocatielijst();
            
$data['leveringsmethodes'$this->maakLeveringsmethodelijst();
            
$this->load->view('v_template',$data);
        
    

I would say that if i’m not logged in, he should take me to the view v_message and say “hold on my friend, you have no access or are not logged in”. And is does that, but, it also loads the view given in plaatsbestelling();.

So how can i say, if you are not logged in, go to v_message and stop right there.
I tried the die(); function, but that just returns a blank page.

I kinda solved this by doing an if in my function:

public function plaatsbestelling()
    
{        
        
if(!$this->is_logged_in()){

        }
    } 

but i’m thinking common there must be a neater way to do this?

 
Posted: 25 May 2012 02:58 AM   [ # 1 ]   [ Rating: 0 ]
Joined: 2012-05-18
6 posts

anyone?

 
Posted: 25 May 2012 03:06 AM   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6593 posts

You need to check to see if the user is logged in or not in your controllers index function,
if they are not logged in redirect them to the login form view else load your normal view.

 Signature 

Certified State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

Skype: insitfx

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View