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

(This post was last modified: 01-26-2015, 05:35 AM by sv3tli0.)

(01-26-2015, 05:05 AM)behnampmdg3 Wrote: That's not what the manual says!

PHP Code:
$CI =& get_instance();

$CI->load->helper('url');
$CI->load->library('session');
$CI->config->item('base_url');
etc

I am talking about pure PHP nothing related to CI..

Here is working example of your first post class

PHP Code:
class Generate_token  
{
    public function 
__construct()
        {
            
$this->CI =& get_instance();
        }
      
    public function 
generate()
        {
            
$raw_random_bytes mcrypt_create_iv(6MCRYPT_DEV_URANDOM);
            
$encoded_random_bytes base64_encode($raw_random_bytes);
            
$token strtr(trim($encoded_random_bytes'='), array('+' => '-''/' => '_'));
            if(
$this->validate($token)==$token)
                {
                    return 
true;
                }
        }
    public function 
validate($token)
        {
            
$sql "SELECT id FROM url_tokens WHERE short_url = ?";
            
$query $this->CI->db->query($sql, array($token));
            if(
$query->num_rows==0)
                {
                    return 
$token;
                }
            else
                {
                    
$this->generate();
                }    
        }    


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..
Best VPS Hosting : Digital Ocean
Reply


Messages In This Thread
RE: Call to a member function validate() on a non-object using own library - by sv3tli0 - 01-26-2015, 05:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB