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

[eluser]kelye[/eluser]
hello
i have the following problem...

Code:
MY_Input.php

class MY_Input extends CI_Input {
    var $CI;
    
    function My_Input()
    {
        parent::CI_Input();
        $this->CI =& get_instance();
    }
}

and i get a "Fatal error: Call to undefined function get_instance() ..."
#2

[eluser]kelye[/eluser]
ok... found the problem

Input is a core class that loads and instantiates automatically BEFORE the Base4/5.php loads (where get_instance() is)

i think it would be nice to add a clear warning in docs about this
#3

[eluser]tonanbarbarian[/eluser]
Yes there are a few things that are loaded before the controller
Once the controller is loaded a reference is made to the input class inside the controller so that you can access it there

If you need to extend the input and you need to access the controller in it here is what I suggest
still keep your CI property but do not instantiate it in the constructor

create a seperate method that can check for an instantiate the CI property and call there in any new code that you write where you might need to access the controller.
This way you dont break the input class and you only use the CI property when you needed it saving resources

Code:
class MY_Input extends CI_Input {
    var $CI = null;
    
    function My_Input()
    {
        parent::CI_Input();
    }

    function _inst() {
      if ($this->CI===null && function_exists('get_instance'))
        $this->CI =& get_instance();
    }

   function something() {
     $this->_inst();
     ...
   }
}
#4

[eluser]kelye[/eluser]
thanks for the answer

the only problem with your code is that i have to call the _inst() function after the script is initialized... and then i will have $CI available

i've used some other functions instead of the resources needed from CI

thanks again




Theme © iAndrew 2016 - Forum software by © MyBB