Loader Class


This class can automatically load MVC and library classes. It can register several automatic class loader functions to load different types of project classes from different directories.
Currently it can load class scripts for models, controller, user and system library classes. The respective directories are configured using constants.


  • getInstance()
  • load_specific_library()
  • initialize_class()
  • user_library()
  • system_library()
  • user_model()
  • user_controller()
  • controller()
  • model()
  • library()
  • core_library()
  • config()

How to use

If your application has a separate file that contains information about paths or information to the database, you can freely add the reserved constants which will contain the names of your directories.

  • MPATH – model directory path
  • CPATH – controller directory path
  • LPATH -library directory path
  • LIBPATH – core library directory path
  • CPATH – config directory path

Initialize Class

// Initialize class or use static methods!

$load = new Loader();
  // or

Load specific user library

First what u need opet your favorite text editor(notepad++) and create new class file with name ‘my_lib.php’ in root/mvc/application/library. After that you can load that library flowing this code:

  // or

This code sample loads a library named “My_Lib“. Class with the name my_lib will be automatically loaded and initialized.

Load specific controller

If you have in your mvc application controller named Blog, you can load blog controller following this code.

  // or

This method load specific controller, retrun object value and  expect one parameter [controller name].

Load specific model

This method load specific user model.

He retrurn object value and expect one parameter [model name].

  // or

Load specific config

This method load specific user config file. If u have config file in your application root/app/config/database.php u can load that file flowing next code:

This method retrurn string or array value and except one parametar [config name]

  // or

If u want to load multiple config files u can use array function like this:

$config = array('database','route','config','my_config');


// or


Add new phth

If u want do add new path and autoload all files from other dir, flow next steps:

First u must add this line code in __constructor


After adding spl_autoload_register function u must create new methot named ‘my_new_direcotry’).

public function my_new_directory($class)
    if ($class) {



Author: Ivan Stojmenovic
Download: Zip | Tar.gz