NanoMVC

Autoloading Plugins

Instead of calling $this->load->library() and $this->load->script() in each controller, you can autoload them so they're always available to every controller by default.

Configuration

Edit your autoload configuration file:

/myapp/configs/config_autoload.php

Auto-loaded Libraries

$config['libraries'] = ['mylib', 'myotherlib'];

If you want to alias a library, use an array with two values: the plugin name and the alias:

$config['libraries'] = [
  ['mylib', 'myalias'],
  ['myotherlib', 'otheralias']
];

Auto-loaded Scripts

$config['scripts'] = ['myhelpers', 'myscripts'];

Script plugins are included globally and their functions are available across all controllers and views.

Auto-loaded Models

$config['models'] = ['mymodel', 'monewmodel'];

You can also autoload models with aliases and specify a connection pool:

$config['models'] = [
  ['mymodel', 'mymodelalias', 'mypool'],
  ['monewmodel', 'mynewmodelalias', 'mynewpool']
];

Declaring Aliases in Your Controllers

To use aliased models and libraries, be sure to declare their properties in your controller. The best way is to extend your base controller and define all the necessary aliases there.

Example:

class My_Controller extends NanoMVC_Controller {
  public $mymodelalias;
  public $mynewmodelalias;
  public $myalias;
  public $otheralias;

  // Add your common controller logic here
}

Then simply extend My_Controller in your controllers instead of NanoMVC_Controller. For instructions on extending controllers, see the Extending NanoMVC Classes documentation.

← to Extending NanoMVC Classes to Getting an Instance →

← Back to Documentation