1ftw1 1ftw1 - 20 days ago 5
PHP Question

Codeigniter ion auth trying to get the user name of a logged in user in to a string

Hi team i am new to CI and ion auth and i want to find the best way to get the user name on the logged user and make it a string. I have try this and im getting an error.

Object of class CI_Email could not be converted to string

This is my Controller

class Dashboard extends CI_Controller {

function index() {
$user = $this->ion_auth->user();
$email = $user->email;

$data['email']= $email;
$data['mainContent'] = 'dashboard_view';
$this->load->view('template', $data);
}


and view

<div id='dashboarWap'>
<?php echo form_open('dashboard/dashInput'); ?>

<?php echo $email; ?>


Any idea on why i am getting this error would be a big help thanks.

Answer

$this->ion_auth->user() is a DB object.

$this->ion_auth->user()->row(); returns the user object which you can query for first_name, number_of_cats_owned, or whatever.

https://github.com/benedmunds/CodeIgniter-Ion-Auth/blob/2/controllers/auth.php