• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to update value by Events in CodeIgniter 4

#11
@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;
}); 
Reply

#12
PHP.net - Anonymous functions
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

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

#14
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");
}); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#15
Not working Sad
Reply

#16
Try adding the return back, but I don't think that will work.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#17
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.
Reply

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.