Welcome Guest, Not a member yet? Register   Sign In
Call to undefined function get_instance() in MY_Language
#1

[eluser]adamp1[/eluser]
Right I'm trying to extend the Language library to add in language detection and have the following code.
Code:
class MY_Language extends CI_Language
    {
        /**
         * Constructor
         */
        function MY_Language()
        {
            // Call Parent Constructor
            parent::CI_Language();

            // Get CI Instance
            $this->CI = &get;_instance();

            log_message('debug','MY_Language Class Initialized');
        }
}

It says the &get;_instance() function is not defined? I don't get it. I have got the exact code (different names) in a MY_Validation class and it works fine. Why is get_instance not found in the library class.

EDIT: There is a ; in the get_instance() function call, this is a typo on writing the code into the forum post, this ; is not in the actual code I am trying to run. I tried to remove it from the post but for what ever reason the change is not being saved.
#2

[eluser]xwero[/eluser]
the &get; seems like an html entity are you sure is just like that in your other library?

edit : the variable $CI is not defined in the Language library.
#3

[eluser]adamp1[/eluser]
Now I suppose I could stop the constructor needing to setup a instance of CI but that would mean it wouldn't be able to detect the language on class creation, I would need to call a separate function from somewhere in my code, maybe using a hook. Which makes the solution ugly.
#4

[eluser]xwero[/eluser]
just add the variable to the MY_Language class
Code:
class MY_Language extends CI_Language
    {
        
        var $CI;
        /**
         * Constructor
         */
        function MY_Language()
        {
            // Call Parent Constructor
            parent::CI_Language();

            // Get CI Instance
            $this->CI =& get_instance();

            log_message('debug','MY_Language Class Initialized');
        }
}
#5

[eluser]adamp1[/eluser]
Nope that dosn't work, it still says it can't find the get_instance() function.
#6

[eluser]xwero[/eluser]
I see in the codeignitor.php that the language class is loaded before the base file which contains the get_instance function. I guess you could only check for other loaded libraries with a hook.

I think the reason why the other library works is because you access the functions in a controller.
#7

[eluser]adamp1[/eluser]
I tried to find where it was loaded at but couldn't find it. Oh well it seems I will have to find another solution, I don't get why some libraries are loaded before the Base file is, and then it isn't documented in the user guide.

Thanks for the help




Theme © iAndrew 2016 - Forum software by © MyBB