Load method
Load method from class SENE_Controller is for loading a model class into controller.
The model will be instantiate as part of properties on SENE_Controller.
Without an alias, the instantiate model object will be same as filename without extension php.
Parameters
Load method has 2 parameter, there is the model filename
and model alias
.
$this->load(string $filename_location[, string $alias])
$filename_location
The method load location always relatives to app/model
directory.
So, if we have a model class under app/model/api/hello_model.php
We have to fill the first parameter with api/hello_model
.
Here is the example:
$this->load('api/hello_model');
With this example the hello_model will be part of SENE_Controller class as hello_model
object
Here is the full example:
<?php
class Blog extends SENE_Controller {
public function __construct(){
parent::__construct();
$this->load('api/hello_model');
}
public function index(){
//executing the hello_model object
print_r($this->hello_model->get());
die();
}
}
$alias
The alias purpose is for shorting the name of model that we create into SENE_Controller.
Alias can contain any alphanumeric and underscore.
Here is the example:
$this->load('api/hello_model','h');
With this example the hello_model will be part of SENE_Controller class as h
object
Here is the full example:
<?php
class Blog extends SENE_Controller {
public function __construct(){
parent::__construct();
$this->load('api/hello_model','h');
}
public function index(){
//executing the hello_model object
print_r($this->h->get());
die();
}
}