Autoloading Local PHP Classes

From Littledamien Wiki
Revision as of 23:53, 4 September 2019 by Video8 (talk | contribs) (Created page with "== Objective == Have a mechanism in place to autoload classes to avoid having to place `require_once()` calls throughout the app's files. == Prerequisites == Composer ==...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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]