Call to a member function validate() on a non-object using own library - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Call to a member function validate() on a non-object using own library (/showthread.php?tid=884) |
Call to a member function validate() on a non-object using own library - behnampmdg3 - 01-26-2015 Hi; Why do I get these error? 1 - Code: A PHP Error was encountered 2 - http://grab.by/E7A2 Main controller: PHP Code: $this->load->library('generate_token'); Library: PHP Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Cheers RE: Call to a member function validate() on a non-object using own library - stopz - 01-26-2015 I'm assuming this error means $CI is not an object. Like its not being defined like Code: $CI = New Generate_token(); Code: $this->load->library('generate_token'); Code: $this->generate_token->validate($token); //Please anybody correct me if i'm wrong. I'm also very new to CI but i'm trying to help as much as i can with my little knowledge of PHP RE: Call to a member function validate() on a non-object using own library - behnampmdg3 - 01-26-2015 (01-26-2015, 04:15 AM)stopz Wrote: I'm assuming this error means $CI is not an object. Like its not being defined like Hey friend; Doesn't really make sense what said. I want to call generate() not validate(). I am following everything like the manual RE: Call to a member function validate() on a non-object using own library - stopz - 01-26-2015 try: Code: $result = $this->generate_token->generate(); RE: Call to a member function validate() on a non-object using own library - behnampmdg3 - 01-26-2015 (01-26-2015, 04:29 AM)stopz Wrote: try: That is exactly what I am doing See post #1 RE: Call to a member function validate() on a non-object using own library - behnampmdg3 - 01-26-2015 I fixed it but I don't like the solution! I am surprised it works this way! PHP Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); RE: Call to a member function validate() on a non-object using own library - sv3tli0 - 01-26-2015 Just a notice... When you have in constructor : $CI =& get_instance(); You can not reuse this variable into methods, because it is only at constructur.. Instead make: $this->CI =& get_instance(); And at methods replace $CI with $this->CI RE: Call to a member function validate() on a non-object using own library - behnampmdg3 - 01-26-2015 (01-26-2015, 04:40 AM)sv3tli0 Wrote: Just a notice... Hey; That's not what the manual says! PHP Code: $CI =& get_instance(); RE: Call to a member function validate() on a non-object using own library - sv3tli0 - 01-26-2015 (01-26-2015, 05:05 AM)behnampmdg3 Wrote: That's not what the manual says! I am talking about pure PHP nothing related to CI.. Here is working example of your first post class PHP Code: class Generate_token When you are in Class you can call methods from the same class using $this->methodname() When you are in class and want to call method from some class loaded with CI you can use $this->CI->classs->method name() but first inside class constructor you have to set $this->CI to get instance of CI.. RE: Call to a member function validate() on a non-object using own library - CroNiX - 01-26-2015 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 { |