Symfony – Autoload.yml – Basic Usage
Autoloading is the term used to describe the process where class files are loaded at the first http request (and cached for subsequent requests). The main benefit of autoloading is that you don’t need to add a bunch of ‘require_once’ calls to your classes to get things working, they are all autoloaded for you. Some may see this autoloading as ‘bloat’, but if strategically cached, it does allow for easier coding within the symfony framework.
Chances are you have some custom classes which are specific to your actual business needs. Rather than stuffing these custom classes in the core symfony directories (lib/model, lib/forms, lib/filters), which they don’t belong, you can create custom directories and then tell symfony about them so symfony can autoload them as if they were the core symfony directories.
Check out the following example:
custom_app: #Unique identifier for autoloading anything in given dir name: Custom app classes #Something that makes sense to you ext: php #You can load files with specific extensions path: %SF_LIB_DIR%/app #The directory from which symfony should autoload files, in this case lib/app recursive: true #Whether to load files within nested dirs
As you can see, autoloading in symfony allows for flexible lib structures, which allows you to better structure your classes for faster development and easier maintenance.
Thanks to Tix comment, you want to add autoload.yml files to /apps/<app_name>/config/autoload.yml
Thanks to German Rumm’s comment, be sure that autoload: is the first line in your autoload.yml file.
Also, here is an actual example:
autoload: sfcustom_api: name: Symfony specific custom apis ext: php path: %SF_LIB_DIR%/MyCustom/api recursive: true
- Symfony – Share Template Across Multiple Apps
- PHP – Symfony – Speed up CLI Commands – Do Not Load Web Plugins
- PHP – Symfony – Build Model – No yml schema found
- Symfony – Propel – Determine Propel Version
- Symfony – Doctrine – Call to a member function evictAll on a non-object
- Symfony – Standard API for Logging Using __callStatic
- Symfony – Symfony 2 Security Audit Results
- Symfony – Serve External Apis from External Hosts – jQuery – Yui
- Symfony – sfGuardPlugin – Use Email Instead of Username
- Symfony – PHP – Possibly Forking 1.x so Invested Companies don’t Lose Millions