Dynamic components


(C) #1

My application uses advanced template.

I have a set of db-driven components (ie not defined in common/config/main.php).
I have a function which adds these components to the application. I have no issue if calling this function at the beginning of a controller action and am able to access the component. However it is not ideal to repeat the code where they are required.

Where is the best place to call this function so these dynamic components available? I have tried setting bootstrap property in config file but this function is not a component.


(C) #2

No one knows?


(Johnson) #3

Hello there,

You can initiate the components in on “beforeRequest” event.

https://www.yiiframework.com/doc/guide/2.0/en/structure-applications#application-events