tags:

views:

129

answers:

2

Hello guys, i have start working with CodeIgniter, but i can't understand one think. How do i load one class into another?

$this->load->library("hello_world");

This is not working?

my class -> load -> hello_world class

class myclass {
      function test() {
         $this->load->library("hello_world");
         $this->hello_world->hello();
      }
}

Message: Undefined property: myclass::$load

A: 

You have to extend the CI controller/model

e.g.

class Some_controller extends Controller
{
    public function index() {}
}
Yorick Peterse
That is actualy for controllers and not for librarys. I think he is asking how to include a library?
streetparade
yes, I was asking for library
Mention that next time :P
Yorick Peterse
A: 

The ability to load a class depends on the load->library function being available. It is made available to the controller and model classes, but extending these may not be appropriate for your use.

Instead you can either get a reference to CI and use that to load and refer to your class, or you can load it as usual in PHP ($c = new MyClass).

To get a rerence to CI use the following:

$CI =& get_instance();

$CI->load->helper('url');
$CI->load->library('session');
$CI->config->item('base_url');
etc.
Kurucu
I did work, thanks :)