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

While loading the model from sub directory, the path prefix will not instantiate as object model name.

So, be careful for choosing the naming class model or alias.

If necessary, you can duplicate a model class to avoid conflict with extra suffix with number.

example, app/model/api/hello_model2.php and then the class name Hello_Model2.

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

Tips

If you confused how to fill the alias name, you can get from first letter of each class name.

example, app/model/api/hello_detail_model2.php and then the alias will be hdm2.