Lib method

The lib method purpose is for loading a library class into a controller by generating (instantiating) a new property inside current controller class. The new property name will be same as library filename without .php extension in lowercase.

This lib method only affected for single file class library.

For using 3rd party library like from composer you can read it from 3rd library section.

Basic Usage

Here is the basic usage for cdn_url method from SENE_Controller class.

$this->lib(string $lib_filename[, string $alias[, string $load_type="lib"]])

Parameters

This method has 1 required parameter and 2 optional parameter.

$lib_filename

The $lib_filename value can be contain a string of library filename. File location of library always relatives to kero/lib directory. So, if we have a library class under kero/lib/seme_email.php we have to fill the first parameter with seme_email without .php extension.

$alias

The $alias value can be contain a string that override the name of property that instantiated by this method.

$load_type

The $load_type determine load mechanism of this method. Here is the list of compatible values:

  • The lib value for loading the library and then automatically instantiate a property.
  • The inc value is for only load the library.
If $load_type value is not equal to lib, the alias parameter value will ignored.

Example

On this example, will show the implementation of lib method without an alias.

<?php
class Blog extends SENE_Controller {
  public function __construct(){
    parent::__construct();
    $this->lib('seme_email');
  }
  public function index(){
    //executing the seme_email object
    $this->seme_email->from('daeng@example.com')
    ....
  }
}

Using Alias

On this example will show the implementation of lib method with an alias.

<?php
class Blog extends SENE_Controller {
  public function __construct(){
    parent::__construct();
    $this->lib('seme_email','eml');
  }
  public function index(){
    //executing the hello_model object
    $this->eml->from('daeng@example.com')
    ....
  }
}

Tips

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

example, kero/lib/seme_email.php and then the alias will be se.

Only Load

On this example will show the implementation of lib method load only mode (inc). The library SEME_Email have to instantiated manually.

<?php
class Blog extends SENE_Controller {
  public function __construct(){
    parent::__construct();
    $this->lib('seme_email','eml','inc');
  }
  public function index(){
    //executing the hello_model object
    $eml = new Seme_Email();
    $eml->from('daeng@example.com');
    ....
  }
}

Info

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

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

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

example, kero/lib/seme_email2.php and then the class name Seme_Email2.