CodeIgniter Forums
How to update value by Events in CodeIgniter 4 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: How to update value by Events in CodeIgniter 4 (/showthread.php?tid=78988)

Pages: 1 2


RE: How to update value by Events in CodeIgniter 4 - ciddict - 04-09-2021

@iRedds,

Should I use function(&$array) here in my code?

PHP Code:
use CodeIgniter\Events\Events;

Events::on('add_value_to_array', function(&$array) {
    error_log("add_value_to_array" PHP_EOL3"events.txt");
    array_push($array"new");
    return $array;
}); 



RE: How to update value by Events in CodeIgniter 4 - InsiteFX - 04-09-2021

PHP.net - Anonymous functions


RE: How to update value by Events in CodeIgniter 4 - ciddict - 04-09-2021

@InsiteFX, I don't understand from there.
Can you please give me the code for my case?


RE: How to update value by Events in CodeIgniter 4 - InsiteFX - 04-09-2021

I did not test this but try it no time right now.

PHP Code:
use CodeIgniter\Events\Events;

Events::on('add_value_to_array', function() use (&$array) {
    error_log("add_value_to_array" PHP_EOL3"events.txt");
    array_push($array"new");
}); 



RE: How to update value by Events in CodeIgniter 4 - ciddict - 04-09-2021

Not working Sad


RE: How to update value by Events in CodeIgniter 4 - InsiteFX - 04-09-2021

Try adding the return back, but I don't think that will work.


RE: How to update value by Events in CodeIgniter 4 - iRedds - 04-09-2021

Sorry, I was wrong.

Events have one direction.
If you need to modify the data and get it back, then it is better to use a simple function instead of using events.

If you still want to use events, then it's easier to implement through object wrapping.
Objects are always passed by reference.


RE: How to update value by Events in CodeIgniter 4 - ciddict - 04-09-2021

OK. I'll check that. Thanks @iRedds and @InsiteFX.