Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
29 lines (22 sloc) 1.1 KB

Class autoloading

Since Yii uses Composer to manage packages, classes from these packages are automatically loaded without the need to require their file explicitly. When packages are installed, a PSR-0 compatible autoloader is generated. To use it, require_once autoloader /vendor/autoload.php in your index.php entry point file.

Autoloader is used not only for the packages being installed but for your application, that is also a package. To load classes of a certain namespace, the following should be added to composer.json:

    "autoload": {
        "psr-4": {
            "App\\": "src/"

Where App\\ is a root namespace and src/ is a directory where classes are located. You can add more source roots if needed. When done, execute composer dump-autoload and classes from the corresponding namespaces will be loaded automatically.


You can’t perform that action at this time.