Question

This is my first project using both Codeigniter and Ion Auth and I've finished this tutorial: http://www.rappasoft.com/tutorials/view/5#.U1bJLeZdWpo

But now that I've reached the end, I have an error that is appearing when all of my code looks identical to the tutorial. The error is:

Message: Creating default object from empty value

Filename: core/MY_Controller.php

Line Number: 13

But the odd thing is that the code from the MY_Controller file is copied right from the tutorial. Here's the code I have:

<?php

if ( ! defined('BASEPATH')) exit('No direct script access allowed');  

class MY_Controller extends CI_Controller {
    public function __construct() {
       parent::__construct();

       if (!$this->ion_auth->is_admin()) {
            redirect('auth/login');
       } else {
            //Store user in $data
            $data->user_info = $this->ion_auth->user()->row();
            //Load $the_user in all views
            $this->load->vars($data);        
       }
    }
}

?>

The correct view loads underneath the error but obviously I'd like to know what's wrong. Since this is my first turn time working with ion-auth and I'm relatively new to code igniter as well, I was wondering if anyone knew how to go about debugging an error like this. Teach a man to fish, feed him for a lifetime! I'd really appreciate not just solutions but methods so I can learn and do this on my own.

Was it helpful?

Solution

Are you working on PHP 5.4+ ?

In that case, you must declare $data before using it:

Change:

$data->user_info = $this->ion_auth->user()->row();

to

$data = new stdClass(); 
$data->user_info = $this->ion_auth->user()->row();

and try again. Hpe it helps!

OTHER TIPS

I think I might have figured it out. I think the issue might be that the default login information (the ones provided by ion auth) do not have any additional information in the database. This means that when the $data variable goes to set the additional account information, it doesn't find anything. It's not a strong enough error to crash the page but it is warning me that there is no other account information available even though it is supposed to be looking for more info.

So how to fix this? Create a user for testing purposes with a full compliment of account information and see if that solves the problem. The only problem is that I don't know how to add new users using ion auth and my views aren't sophisticated enough yet to make that process easy.

I've looked at the create_user() method in the auth.php file but when you press submit after filling out the form, it kicks you back to the same page with all the info. I have a feeling an edit needs to be done here although I don't quite know what to change. I've been looking on the ion auth documentation but it seems a bit... sparse. I think I'm on the right track although I'd really like to hear if someone else has a better explanation or solution. As of now, I haven't actually fixed it yet. Just deduction.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top