Welcome Guest, Not a member yet? Register   Sign In
Can't call custom library functions in my extended model (upgrading from 1.7.2. to 2.0.2)
#1

[eluser]ray023[/eluser]
I have an extended model:

Code:
class MY_Model extends CI_Model
{
    protected $is_admin = false;
    protected $facility_id = 0;
    protected $current_user = 'not set';
                    
    public function __construct()
    {
        parent::__construct();
        $this->load->library('ion_auth');
        //Blows up here:        
        $user    =    $this->ion_auth->get_user();
        
    }

The function in the ion_auth will not get called.
I get the following message:
Message: Undefined property: Welcome::$ion_auth
And then the following error:
Fatal error: Call to a member function get_user() on a non-object in c:\...\application\core\MY_Model.php on line 30

The library is loaded, but even when I do something like this it doesn't get called:
Code:
$CI =& get_instance();
        $CI->load->library('ion_auth');
        echo $CI->ion_auth->get_user();
    }

What could I have configured wrong during the upgrade?

NOTE: my extended controller is working fine.
#2

[eluser]toopay[/eluser]
Code:
// Is this typo error or actual code? '->->', and if its returned array use var_dump or print_r instead echo!
echo $CI->ion_auth->->get_user();
#3

[eluser]ray023[/eluser]
[quote author="toopay" date="1303353354"]
Code:
// Is this typo error or actual code? '->->', and if its returned array use var_dump or print_r instead echo!
echo $CI->ion_auth->->get_user();
[/quote]

Excellent question and yes, it was a typo (sorry)...post corrected.

Also, FWIW, I *did* use var_dump when testing this morning. I just quickly typed out the code above in my post because I removed that piece of code from my project after testing..
#4

[eluser]Ben Edmunds[/eluser]
ray023,

First thing you should fix is to move the loading of Ion Auth out of the My_Model constructor. It should either be in a MY_Controller or autoloaded. In this case I would recommend autoloading it.
#5

[eluser]ray023[/eluser]
[quote author="Ben Edmunds" date="1303416654"]ray023,

First thing you should fix is to move the loading of Ion Auth out of the My_Model constructor. It should either be in a MY_Controller or autoloaded. In this case I would recommend autoloading it.[/quote]

Hey Ben, thanks for the feedback. I actually do have Ion Auth loading in my extended controller. The above example was merely to demonstrate I can't get it to load in my extended model at all. It worked fine in 1.76, but it's an issue trying to upgrade 2.0.2.

It's not just Ion Auth either. I have another, much simpler, extended library that's not loading correctly in my extended model either. I'm sure I'm doing something wrong, but just haven't figure out exactly what yet.
#6

[eluser]Ben Edmunds[/eluser]
I spoke to _kennyk_ about this and he has committed a fix for it. Try CI Reactor tip and let me know what you get.
#7

[eluser]ray023[/eluser]
[quote author="Ben Edmunds" date="1303528280"]I spoke to _kennyk_ about this and he has committed a fix for it. Try CI Reactor tip and let me know what you get.[/quote]

Bah...technical difficulties. Tongue I need to backup and regroup.

I'm reverting back to my 1.7.2. code and going to try this again.

Are you saying the code found here contains the fix I need from kennyk?

I ask for two reasons:
1. I was working with core
2. The commits on the link above are only from Greg Aker.
#8

[eluser]Ben Edmunds[/eluser]
From what I was told, a CI core commit is causing issues with the loader.

Try the code here (core): https://bitbucket.org/ellislab/codeignit...7258aa2bc0

or here (reactor): https://bitbucket.org/ellislab/codeignit...653e19b906


Let me know what happens, if neither one of these work I'll dig through the code and figure out what's up.
#9

[eluser]ray023[/eluser]
Started from scratch with the recommended download; still not working.

I still get the following error:
Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined property: Auth::$ion_auth
Filename: core/Model.php
Line Number: 50

I'll get the same type of error if I do something like this:
Code:
echo $this->calendar->generate(2006, 6);

However, if I add calendar to the autoload file, it will render the calendar.

Any thoughts on how to troubleshoot so I can give you better info or fix this myself?
#10

[eluser]Ben Edmunds[/eluser]
Ray,

Which download did you use? I will try to duplicate.




Theme © iAndrew 2016 - Forum software by © MyBB