CodeIgniter Forums
Events (SOLVED) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Events (SOLVED) (/showthread.php?tid=87873)



Events (SOLVED) - SubrataJ - 06-12-2023

Can we do this by extending Events?
PHP Code:
This s my CustomEvents.php file ---
<?
php
namespace App\Events;
use 
CodeIgniter\Events\Events;
use 
App\Hooks\ProviderHooks;
$pHooks = new ProviderHooks();
// // Events::on('clientAdded', static function ($foo, $bar, $baz) {
// //    echo 'Hola Amigos';
// // });

Events::on("ClientAdded", [$pHooks"clientAdded"]); 

when I tryna trigger this by  
PHP Code:
\CodeIgniter\Events\Events::trigger('ClientAdded'); 
it's not working unless I define these events in Event.php

do I have to mention all the events on Events.php?


RE: Events - kenjis - 06-12-2023

You need to load your CustomEvents.php by yourself.

For example,
add `require 'path/to/your/CustomEvents.php';` in app/Config/Events.php.


RE: Events - SubrataJ - 06-12-2023

(06-12-2023, 04:44 PM)kenjis Wrote: You need to load your CustomEvents.php by yourself.

For example,
add `require 'path/to/your/CustomEvents.php';` in app/Config/Events.php.

Thank you @kenjis I was thinking of this but I don't know why I didn't try. Now it's working as expected.