I'm sure many developpers wonder what is the real difference between these two functions, that are the main functions of the core ^^
I know that trigger_event returns the var $data but, except that, they are almost identical, so why two functions ?
It appears that we use trigger_action to detect a precise point of the core, although trigger_event is used to compute datas but looking at the prototype
function trigger_action (string $event [, mixed $data=null ] )
also accept more arguments
rvelices this is for you ! :-)
Last edited by mistic100 (2011-06-24 19:22:00)
Offline
mistic100 wrote:
I know that trigger_event returns the var $data but, except that, they are almost identical, so why two functions ?
Well, this is enough. No ? Also note that in the case of an event, the $data might change as it goes through the handlers. In the second case it is going to be the same...
Offline
rvelices wrote:
Well, this is enough. No ?
yeah, but for that we don't need two functions, we can call strtotime without print the result
and each time trigger_action is called, no $data is given (that's not a rule but a fact)...
Last edited by mistic100 (2011-06-24 21:24:28)
Offline
mistic100 wrote:
yeah, but for that we don't need two functions, we can call strtotime without print the result
I don't understand...
mistic100 wrote:
and each time trigger_action is called, no $data is given (that's not a rule but a fact)...
In admin/batch_manager_global.php, you have:
trigger_action('element_set_global_action', $action, $collection);I added this to trigger actions on batch manager with thumbnails regeneration and websize regeneration...
We don't need trigger_event here, but trigger action...
Offline
P@t wrote:
mistic100 wrote:
yeah, but for that we don't need two functions, we can call strtotime without print the result
I don't understand...
I just want to say that the only fact that a function returns something and the other doesn't not require two differents functions
P@t wrote:
mistic100 wrote:
and each time trigger_action is called, no $data is given (that's not a rule but a fact)...
In admin/batch_manager_global.php, you have:
Code:
trigger_action('element_set_global_action', $action, $collection);
ok, so what append here if we use trigger_event ?
I don't want to change the code, it works fine, I want to understand why there is two functions...
Offline
mistic100 wrote:
Code:
trigger_action('element_set_global_action', $action, $collection);ok, so what append here if we use trigger_event ?
If you use a trigger_event here, your plugin need to return $action for other plugins.
It's not the same usage... so it's clearer to have two different functions, isn't it?
Offline
okay !! I understand
we can say that with 'trigger_event' events are in series, and with 'trigger_action' events are parralels (its minded : in PHP all is in serie)
Offline
rvelices wrote:
Also note that in the case of an event, the $data might change as it goes through the handlers. In the second case it is going to be the same...
:-)))
Note that with trigger_action, events are not really "in parallel", events are still loaded with the priority parameter (default 50).
Offline