2

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

1
  • where do you saved your class? in application/library ? Commented Jun 5, 2010 at 20:29

2 Answers 2

6

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.
Sign up to request clarification or add additional context in comments.

Comments

1

You have to extend the CI controller/model

e.g.

class Some_controller extends Controller
{
    public function index() {}
}

1 Comment

That is actualy for controllers and not for librarys. I think he is asking how to include a library?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.