Welcome Guest, Not a member yet? Register   Sign In
Call to a member function validate() on a non-object using own library
#10

(This post was last modified: 01-26-2015, 02:35 PM by CroNiX.)

Sure, you can load the CI superglobal object in EACH of your classes methods if you wish (like the very limited example in the userguide shows), or you can make it available to all methods.

Code:
class Yourclass {
  private $CI; //create a attribute for the CI superglobal

  public function __construct()
  {
    $this->CI =& get_instance(); //make CI available to all methods
  }

  public function some_method()
  {
    //use the CI property instead of using $CI =& get_instance() in each method
    $this->CI->load->helper('url');
  }

  public function another_method()
  {
    //again, we already loaded CI in the __construct(), so just use it!
    $some_var = $this->CI->input->post('some_var', TRUE);
  }
}
Reply


Messages In This Thread
RE: Call to a member function validate() on a non-object using own library - by CroNiX - 01-26-2015, 02:34 PM



Theme © iAndrew 2016 - Forum software by © MyBB