Welcome Guest, Not a member yet? Register   Sign In
Instantiating an object from a library class and calling methods/functions on that object
#1

[eluser]Unknown[/eluser]
Hello All,
I'm quite new to PHP and CI, so I request your indulgence if this may be a simple question. I wanted to know how to instantiate a class which is declared as a library and call a method on the instantiated object.

I'm loading a library in a view:
Code:
$this->load->library('blah');
$data = $this->blah->get_stuff('stuff');

And I get the following error in the php error log:
PHP Fatal error: Call to a member function get_stuff() on a non-object

What do I need to do to instantiate a class object from a class declared in a library?

Do I need to have a something in the constructor in the class that I want to instantiate?

I've pasted example code below:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Blah
{  
   private $CI = NULL;
  
  
   /**
    * Constructor
    */
   public function __construct()
   {
     $this->CI =& get_instance();
     $this->CI->load->helper('url'); // load the url helper
     return($this);
   }
      
      
   public function get_tabset()
       {
         $tabs = array(array("args" => array("red","green","blue"),
                             "name" => "this tab",
                             "url" => "http://www.example.org/stuff"));

          
         return($tabs);
       }
}

?>

Would appreciate any insight into figuring out how this is done.
TIA




Theme © iAndrew 2016 - Forum software by © MyBB