-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inter module communication #28
Comments
Not quite sure what are you talking about exactly. Yii2 has event support i.e. you can do $component->trigger('myEvent'); and then anything can subscribe to an event like the following: $component->on('myEvent', function($event){ ... }); What's different from 1.1 is syntax and the fact that you don't need to declare event prior to raising it. |
Moreover, with typical application flow there's only one module running at a time and we aren't going to change it. |
👍 for inter module communication. Would be really cool if we could do this from module 1: Yii:app()->trigger( 'mod_1.xyz', new Mod1Event() ); and this in config or onAppInit(): Yii::app()->on('mod_1.xyz', function(Mod1Event $event) {
Yii::app()->getModule('mod_2')->abc( $event->whatever );
}); And I think it should be possible with the new event system, shouldn't it? |
Yes, this is possible in Yii 2. You can define and use whatever events. |
cool |
@mashhadi i think i fully understand what 's your meaning ! even yii2 support new "event" model, the above scenario should be designed carefully . lets say yii2 's new event system: Yii::app()->on('mod_1.whatEverStringNameAsEvent, function(CEvent $event) { here i just give my way : you first define what event may be triggerred from one module , then use db to hold the listener list from another modules . when a module event fired the first thing is to look for all the listeners which listen to this event! for now yii2 (even sf1 eventDispatcher ) event system handle this thing is some thing like this : you first should register the listeners , you see you must "listen" the specific event before the event triggerred in same request thread ! but this may be wasteful if that event do not fire ( a event may be only triggerred on some specific condition ) . so even the yii2 support unpredefined event model , you will have to design it yourself to handle the module comunication ! in sns project the user related modules will not be foreknew (both the number and the content type !). usually these module can be installed and unistalled automatically , you can register the module event listeners in the install process ( you need insert records to module_event and module_listener table :) ,and do it in a reverse way in the uninstall process)! |
@yiqing-95 yes, i exactly mean the same thing, i have already implemented a similar approach but not involving any db, In every module i have a Event Handler class, i write all handlers in this class. Whenever an event is raised it check for EventHandler classes in all modules and call respective handlers. Your approach seems to be better as you can prioritize your handlers, but in my case that is not needed. |
Translated structure-filters.md and structure-widgets.md. [skip ci]
I am not sure what is the best place to put wish list, But it would be really help full if the framework provides some better approach for raising and handling events between different modules. Application level interrupts you can say.
like if a user save function is called, i can handle beforeSave afterSave of User model, in some other module.
The text was updated successfully, but these errors were encountered: