Yii2 IDE Autocomplete Helper
Autocompletion generator for custom components in Yii2., (*1)
, (*2)
, (*3)
[English documentation] [Документация на русском], (*4)
By default in Yii2 not working autocompletion for custom components. IDE sees no added components and this causes inconvenience in operation., (*5)
This extension allows you to automatically generate a file with the autocomplete PHPDoc blocks with which the IDE will recognize all of the components in the application configuration., (*6)
Installation
Using Composer:, (*7)
composer require "iiifx-production/yii2-autocomplete-helper"
Configuration
After installation, you need to one-time set up component to work., (*8)
For Yii2 Basic, in @app/config/console.php:, (*9)
'bootstrap' => ['log', 'autocomplete'],
'components' => [
'autocomplete' => [
'class' => 'iiifx\Yii2\Autocomplete\Component',
],
# ...
]
For Yii2 Advanced, in @console/config/main.php:, (*10)
'bootstrap' => ['log', 'autocomplete'],
'components' => [
'autocomplete' => [
'class' => 'iiifx\Yii2\Autocomplete\Component',
],
# ...
]
Using
To generate autocompletion in the console:, (*11)
php yii ide-components
Generator automatically detects the type of application, read all configuration files and generate the autocomplete file to the application root., (*12)
Yii2 IDE auto-completion helper
Vitaliy IIIFX Khomenko, 2019
Success: /home/iiifx/Projects/myProject/_ide_components.php
Important: For IDE did not swear on the two copies of the Yii class must be main Yii class file marked as a text document - example.
The main class is located on the way: @vendor/yiisoft/yii2/Yii.php, (*13)
Advanced customization
Sometimes the structure of the application differs from the standard and the need to change the generator behavior., (*14)
The following are examples of possible configuration options., (*15)
Changing the name of the component
If you need to change the name of a autocomplete to another, it is quite simple:, (*16)
'bootstrap' => ['log', 'new-component-name'], # <-- new component name
'components' => [
'new-component-name' => [ # <-- new component name
'class' => 'iiifx\Yii2\Autocomplete\Component',
],
# ...
]
When the generator run in the console you need to pass the correct component name:, (*17)
php yii ide-components --component=new-component-name
Changing environment
By default, a generator start is only possible for YII_ENV = "dev" environment., (*18)
You can change the environment:, (*19)
'bootstrap' => ['log', 'autocomplete'],
'components' => [
'autocomplete' => [
'class' => 'iiifx\Yii2\Autocomplete\Component',
'environment' => 'local', # <-- environment
],
# ...
]
Changing the generator controller
By default, the generator uses a console controller to create autocompletion., (*20)
You can replace the default controller, extend it, or add your own implementation:, (*21)
'bootstrap' => ['log', 'autocomplete'],
'components' => [
'autocomplete' => [
'class' => 'iiifx\Yii2\Autocomplete\Component',
'controllerMap' => [
'ide-components' => 'iiifx\Yii2\Autocomplete\Controller', # <-- default controller
'my-custom-generator' => 'path\to\your\custom\Controller', # <-- your controller
],
],
# ...
]
Now you can run your controller:, (*22)
php yii my-custom-generator
Link to the controller by default: source/Controller.php., (*23)
Changing the autocompletion file
By default, autocompletion file will be named _ide_components.php and will be placed in the application root., (*24)
You can change the name and location of the file:, (*25)
'bootstrap' => ['log', 'autocomplete'],
'components' => [
'autocomplete' => [
'class' => 'iiifx\Yii2\Autocomplete\Component',
'result' => '@app/new-file-name.php' # <-- name and path
],
# ...
]
The file path must be relative to aliases framework. Example: @common/../new-file-name.php., (*26)
Special configuration files
Sometimes you need to manually specify the application configuration files from which you want to generate autocompletion., (*27)
In this case, the generator will not seek configuration, the generator immediately uses this list., (*28)
For Yii2 Advanced:, (*29)
'bootstrap' => ['log', 'autocomplete'],
'components' => [
'autocomplete' => [
'class' => 'iiifx\Yii2\Autocomplete\Component',
'config' => [
'@common/config/main.php', # <-- config list
'@common/config/main-local.php',
'@console/config/main.php',
'@console/config/main-local.php',
'@backend/config/main.php',
'@backend/config/main-local.php',
'@frontend/config/main.php',
'@frontend/config/main-local.php',
],
],
# ...
]
For Yii2 Basic:, (*30)
'bootstrap' => ['log', 'autocomplete'],
'components' => [
'autocomplete' => [
'class' => 'iiifx\Yii2\Autocomplete\Component',
'config' => [
'@app/config/console.php', # <-- config list
'@app/config/web.php',
],
],
# ...
]
Configuration groups
In big projects sometimes need to be able to generate different autocomplete files depending on the stage of development., (*31)
You can group configuration files and generate autocompletion only for a specific group., (*32)
'bootstrap' => ['log', 'autocomplete'],
'components' => [
'autocomplete' => [
'class' => 'iiifx\Yii2\Autocomplete\Component',
'config' => [
'frontend' => [
'@common/config/main.php', # <-- frontend group
'@common/config/main-local.php',
'@frontend/config/main.php',
'@frontend/config/main-local.php',
],
'backend' => [
'@common/config/main.php', # <-- backend group
'@common/config/main-local.php',
'@backend/config/main.php',
'@backend/config/main-local.php',
],
'api' => [
'@common/config/main.php', # <-- api group
'@common/config/main-local.php',
'@common/../api/config/main.php',
'@common/../api/config/main-local.php',
],
],
],
# ...
]
Now you can generate autocompletion for the desired group:, (*33)
php yii ide-components --config=api
Configuring Application Classes
Some projects can sometimes use overridden application classes for web and console., (*34)
You can do this through the appropriate setting in the config., (*35)
'bootstrap' => ['log', 'autocomplete'],
'components' => [
'autocomplete' => [
'class' => 'iiifx\Yii2\Autocomplete\Component',
'webAppClass' => '\full\namespace\to\WebApplicationClass',
'consoleAppClass' => '\full\namespace\to\ConsoleApplicationClass',
],
# ...
]