Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is $this->load->view() in CodeIgniter

$this is use for current class and view is method but what is load. Is this a property?

Is this example correct?

class super{

    public $property;

    public function superf1()
    {
        echo "hello";
    }
    public function col()
    {
        $this->superf1();
    }

    $this->property->super1();

}
like image 470
anil sidhu Avatar asked Dec 24 '22 09:12

anil sidhu


2 Answers

Yes, load is a property. Think of it like this:

class Loader {
    public function view() {
        //code...
    }
}

class MyClass {
     private $load;

     public __constructor() {
         $this->load = new Loader();
     }

     public someMethod() {
         $this->load->view();
     }
}

This syntax is called chaining.

like image 96
Mihai Răducanu Avatar answered Dec 28 '22 10:12

Mihai Răducanu


Your controller inherits CI_Controller. So, if you look in application/system/core/Controller.php you'll find something interesting : $this->load =& load_class('Loader', 'core'); (l.50 with CI2). So, $this->load refer to the file application/system/core/Loader.php which have a function public function view (l.418 with CI2)

like image 37
Gwendal Avatar answered Dec 28 '22 10:12

Gwendal