Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Push callback event results in an array
Hi,
How could I push each result of a created callback event in an array, or at least, how could I add a delimiter between each result (string) of this event?
Thanks!
Last edited by NicolasGraph (2016-09-19 15:45:59)
Offline
Re: Push callback event results in an array
By using callback_event_ref
?
Offline
Re: Push callback event results in an array
Thanks @planeth; I never used this function but I’ll investigate tomorrow; feel free to tell me more about how you would do it. I thought I could use the $pre
argument of callback_event()
but I’m not sure to understand how it works for now…
Offline
Re: Push callback event results in an array
This is the @callback_event_ref@ definition
Basic you’ve got 2 more parameters which are passed by reference to do anything you want with.
Don’t know exactly what you’re trying to achieve, but should do the trick IMHO.
Offline
Re: Push callback event results in an array
NicolasGraph wrote #301620:
I thought I could use the
$pre
argument ofcallback_event()
but I’m not sure to understand how it works for now…
In theory, it works like this in its array form:
register_callback('my_callback_one', 'my_event', 'my_step', 0);
register_callback('my_callback_two', 'my_event', 'my_step', 0);
function my_callback_one($event, $step, $rs) {
return (array) $rs + array('one' => 'one apple');
}
function my_callback_two($event, $step, $rs) {
return (array) $rs + array('two' => 'two apples');
}
...
$apples = callback_event('my_event', 'my_step', array(0, 0), 'no apples');
After this, $apples
should contain array(0 => 'no_apples', 'one' => 'one apple', 'two' => 'two apples')
.
Offline
Re: Push callback event results in an array
etc wrote #301622:
In theory, it works like this in its array form […]
After this,$apples
should containarray(0 => 'no_apples', 'one' => 'one apple', 'two' => 'two apples')
.
This sounds to be exactly what I was looking for; I just don’t need the first element but I’ll see how to play with that. Thanks (again…) Oleg!
Offline
Re: Push callback event results in an array
You are welcome! Actually, if callback functions always return an array, there is an easier way:
function my_callback_one($event, $step, $rs) {
return array('one apple');
}
function my_callback_two($event, $step, $rs) {
return array('one more apple');
}
$apples = callback_event('my_event', 'my_step', 0, 'no apples, but nobody cares');
This will return Array ( [0] => one apple [1] => one more apple )
. If it works for you, I would prefer this over $pre
array, which is only a hack to patch pluggable_ui
in a bw-compatible way.
Edit: note that in this case $rs = 'no apples, but nobody cares'
in all calls.
Last edited by etc (2016-09-20 09:04:34)
Offline
Offline