Autoloading Local PHP Classes

From Littledamien Wiki
Jump to navigation Jump to search

Objective[edit]

Have a mechanism in place to autoload classes to avoid having to place require_once() calls throughout the app's files.

Prerequisites[edit]

Composer

Edit composer.json to autoload local classes[edit]

Add the following directive to composer.json:

{
  "autoload": {
    "classmap": [
      "Classes/"
    ]
  }
}

Update Composer's autoloader with php composer.phar dumpautoload from the project root directory. [1]

Notes[edit]