Yii2: differences between init() and bootstrap() and best place to add dynamical URLs on a module

做~自己de王妃 提交于 2019-12-11 01:07:34

问题


I dont understand exactly what is the difference between use init() and bootstrap() on a class.

My case:

I want to add dynamical urls from my module by using Yii::$app->urlManager->addRules(...) but NOT loading the module in order to improve the performance.

So, I thought if bootstraping the module from the main configuration file like: 'bootstrap' => ['mymodule'], the Module::bootstrap() function will be executed ONLY and exclusively. But actually always runs Module::init() function, and then Module::bootstrap().

On this documentation http://www.yiiframework.com/doc-2.0/guide-runtime-routing.html#adding-rules say:

'Note that you should also list these modules in yii\web\Application::bootstrap() so that they can participate the bootstrapping process.'

But Module::bootstrap() is not executed if the module is listed on yii\web\Application::bootstrap()

I want to set only the dynamic rules with no module loading. How is it possible? What is the best place to set dynamical URLs with no impact to performance?


回答1:


i decide resolve this issue(adding dynamic rules for module) by watching working extensions.

for example https://github.com/dmstr/yii2-pages-module extension uses bootstrap interface.

don`t forget write in composer.json "type" attribute as "yii2-extension".



来源:https://stackoverflow.com/questions/48443436/yii2-differences-between-init-and-bootstrap-and-best-place-to-add-dynamical

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!