- Seme Framework
- version 4.0.3
- Requirements
- Download & Install
- Configuration
- Tutorials
- URI Routing
- Constants
- Global Variables
- Model
- View
- Controller
- cdn_url
- config
- constructor
- getAdditional
- getAdditionalBefore
- getAdditionalAfter
- getAuthor
- getCanonical
- getContentLanguage
- getDescription
- getIcon
- getJsContent
- getJsFooter
- getJsReady
- getKey
- getKeyword
- getLang
- getRobots
- getShortcutIcon
- getThemeElement
- getTitle
- input
- lib
- load
- loadCss
- loadLayout
- putThemeContent
- putJsContent
- putJsFooter
- putJsReady
- render
- resetThemeContent
- session
- setAuthor
- setCanonical
- setContentLanguage
- setDescription
- setIcon
- setKey
- setKeyword
- setLang
- setShortcutIcon
- setTheme
- setTitle
- Library
- CLI (command line interface)
- Core
- Issue
- Deployment
Load Method
The load
method is used to call a model file or a library file while in the Controller context. This method also allows to instantiate the called file into an object. By default, the name of the instantiated object will be the same as the file name in lowercase. You can also replace the object name with the desired name or give it an alias.
Basic Usage
Here is the basic usage load
method from SENE_Controller class.
$this->load(string $filename_location[, string $alias=''[, string $load_type='model']]):self
Parameters
This method has 1 required parameter and 2 optional parameters.
$filename_location
The $model_filename
value can be contain a string of model filename.
File 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 extra suffix path, like api/hello_model
.
$alias
The alias name of the object that has been called into the controller.
If given an empty string, it will use the file name without the .php
suffix as the object name.
$load_type
The type of call from the file to be called is "model", "lib" or "". If the string is empty, it will call the library but without instantiating it into an object.
Example
On this example, will show the implementation of load
method without an alias.
<?php
class Blog extends \SENE_Controller {
public function __construct(){
parent::__construct();
$this->load('hello_model');
}
public function index(){
//executing the hello_model object
print_r($this->hello_model->get());
die();
}
}
With Alias
On this example, will show the implementation of load
method using alias.
<?php
class Blog extends \SENE_Controller {
public function __construct(){
parent::__construct();
$this->load('api/hello_model','hm');
}
public function index(){
//executing the hello_model object
print_r($this->hm->get());
die();
}
}
Inside a Directory
On this example, will show the implementation of load
method loading a model inside a directory and without an alias.
<?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();
}
}