• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Community-Auth variables?

#1
I'm trying to access the variables inside the controller?

Code:
class Front extends MY_Controller
{
    function __construct()
    {
        parent::__construct();
        
        $this->load->helper('array_object_helper');
        $this->load->helper('array_helper');
        $this->load->model('codesmastery_mdl');
        
        //get languages from DB.
        $languages = $this->codesmastery_mdl->get_languages();    
        $this->session->set_flashdata('flash_msg_lang', $languages);
        
        //Get Community-auth variables
        echo '<b>username: </b>' . $this->auth_username;
      
    }

But unfortunately I got this error
Code:
Message: Undefined property: Front::$auth_username

So why is this happening?
skunkbad can you help me?

thanks in advance.
No SEO spam
Reply

#2
You haven't called any auth method, like is_logged_in, require_role, etc. The variables aren't going to be there until you do. Since you're in the constructor, you might just call $this->is_logged_in() before you need auth_username
Reply

#3
thanks dude.

+1 to make it 20. Wink
No SEO spam
Reply

#4
actually I want the $auth_username in the view.

I tried like this below,
Code:
<?php
                    if(is_logged_in()) {
                        echo $auth_username;
                    }
                ?>

but I got error.

the proper way to acces the variables in view?

thanks in advance.
No SEO spam
Reply

#5
Is_logged_in is a controller method, so call it in the controller with $this->
Reply

#6
Hi skunkbad sorry for this inconvenience.
I re-dig the codes again and I found out the documentation and the actual codes do not matched.

In the documentation for example it says this for view variables.
Code:
$auth_username

But the actual codes said this,
Code:
        // Set user specific variables to be available in all views
        $data = array(
            'auth_user_id'    => $this->auth_user_id,
            'auth_user_name'  => $this->auth_user_name,
            'auth_level'      => $this->auth_level,
            'auth_role'       => $this->auth_role,
            'auth_email'      => $this->auth_email
        );

confusing

lol
No SEO spam
Reply

#7
problem solved.
No SEO spam
Reply

#8
(03-05-2016, 08:06 PM)solidcodes Wrote: Hi skunkbad sorry for this inconvenience.
I re-dig the codes again and I found out the documentation and the actual codes do not matched.

In the documentation for example it says this for view variables.
Code:
$auth_username

But the actual codes said this,
Code:
        // Set user specific variables to be available in all views
        $data = array(
            'auth_user_id'    => $this->auth_user_id,
            'auth_user_name'  => $this->auth_user_name,
            'auth_level'      => $this->auth_level,
            'auth_role'       => $this->auth_role,
            'auth_email'      => $this->auth_email
        );

confusing

lol

You may have an older version of Auth_Controller.php, because auth_user_name was switched to auth_username a while back. This change was made to avoid confusion, but apparently it created some Smile
Reply

#9
Yes I'm using old version of CodeIgniter 3.0 only and older version of Community-Auth.
This is fine for me now, because I'm in a hurry!!!

lol
No SEO spam
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.