anil sidhu
anil sidhu

Reputation: 963

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();

}

Upvotes: 4

Views: 22826

Answers (5)

Nik Patode
Nik Patode

Reputation: 9

In PHP 8.1 use return("viewname", $data)

Upvotes: 0

teenage vampire
teenage vampire

Reputation: 359

load is a class belongs to the loader class codeigniter official documentation

view, model and others are methods

Upvotes: 0

Mihai Răducanu
Mihai Răducanu

Reputation: 12585

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.

Upvotes: 8

DFriend
DFriend

Reputation: 8964

In the context of a class that extends CI_Controller (in other words: a controller) the symbol $this is the Codeigniter "super object". Which is, more or less, the central object for CI sites and contains (among other things) a list of loaded classes. load is one of the classes you'll always find there because it is automatically loaded by the CI system.

Technically, the class creates objects of the type CI_Loader. view() is just one of the many methods in the load class. Other commonly used class methods are model(), library(), config(), helper(), and database(). There are others.

So, in short, load is a class used to load other resources.

Upvotes: 0

Gwendal
Gwendal

Reputation: 1273

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)

Upvotes: 2

Related Questions