It allows putting configuration needed to use a package right inside thus implementing a plugin system. The package becomes a plugin holding both the code and its configuration.
After composer updates its autoload file, and that happens after dump-autoload , require , update or remove , Composer plugin:. In the application entry point, usually index. The web in the above is a config group. The config loader obtains it runtime according to the merge plan.
The configuration consists of three layers that are loaded as follows:. If you are not sure that the configuration group exists, then use the has method:. Each config group represents a set of configs that is merged into a single array. It is defined per package in each package composer.
Absence of files not marked with it will cause exception. It's okay if params-local. It will collect all web. However, if the configuration folder is packaged as part of the PHAR archive, the configuration files will not be uploaded. In this case, you must explicitly specify each configuration file. Output files params-console. You can customize the group name via constructor of Config :.
A number of options is available both for Composer plugin and a config loader. Composer options are specified in composer. The source-directory option specifies where to read the configs from for a package the option is specified for. It is available for all packages, including the root package, which is typically an application. The value is a path relative to where the composer. A configuration file returns a PHP array representing the configuration.
For example, you may keep an application configuration in a file named web. Because the components configuration is complex too, you store it in a separate file called components. The content of components. To get a configuration stored in a configuration file, simply "require" it, like the following:.
The [[Yii::createObject ]] method is implemented based on a dependency injection container. It allows you to specify a set of the so-called default configurations which will be applied to ALL instances of the specified classes when they are being created using [[Yii::createObject ]].
Without using default configurations, you would have to configure maxButtonCount in every place where you use link pagers. Configurations often vary according to the environment in which an application runs.
For example,. With these environment constants, you may specify your configurations conditionally based on the current environment. For example, your application configuration may contain the following code to enable the debug toolbar and debugger in development environment. Configurations often vary according to the environment in which an application runs. For example,. With these environment constants, you may specify your configurations conditionally based on the current environment.
For example, your application configuration may contain the following code to enable the debug toolbar and debugger in development environment. Found a typo or you think this page needs improvement? Edit it on github! The Definitive Guide to Yii 2. Version 2. Go to Top. User Contributed Notes. Leave a comment. The default behavior is to put the protected directory, where all the application files reside, in the same directory as the index file.
My inclination is to move it outside of the Web directory, like so:. Tip: Moving the protected folder outside of the Web root directory is just an extra security precaution. To disable debuggin, remove or comment out that line. I normally just comment it out, so that I can re-enabled debugging later.
Or you can change it to something like this, so that you can add debugging to a page on the fly:. If you do that, then to debug any page on the fly, change the URL from, for example, www. With a framework, the simple loading of the home page could easily involve a dozen actions.
In order to limit the logged i. The last two lines of the bootstrap file include the framework and start the application. As of Yii 1. It is exactly the same as index. However, the test configuration file just includes the main configuration file, then also enables the CDbFixtureManager component, which is used for unit testing.
0コメント