Lib method

Lib method from class SENE_Controller is for loading a library class into controller.

The library will be instantiate as part of properties on SENE_Controller.

Without an alias, the instantiate library object will be same as filename without extension php.

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.

Parameters

Load method has 3 parameter, there is the library filename, library alias and embeeding type.

$this->lib(string $filename_location[, string $alias[, string $embeeding_type="lib"]])
            

$filename_location

The method lib location 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.

Here is the example:

$this->load('seme_email');
            

With this example the seme_email library will be part of SENE_Controller class as seme_email object

Here is the full example:

<?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')
    ....
  }
}
            

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.

$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->lib('seme_email','eml');
            

With this example the seme_email will be part of SENE_Controller class as eml object

Here is the full example:

<?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.

$embeeding_type

The embeeding_type purpose is for enable autoinstantiate object or not.

If value equal to lib, the library will be instantiated with same name as library filename.

Otherwise, the library will be included only wihtout instantiated.

Here is the example:

$this->lib('seme_email','eml','inc');
            

With this example the seme_email will be part of SENE_Controller class as eml object

Here is the full example:

<?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_Emal();
    $eml->from('daeng@example.com');
    ....
  }
}
            

If $embeeding_type value is not equal to lib, the second parameter will ignored.