Welcome Guest, Not a member yet? Register   Sign In
Events (SOLVED)
#1
Big Grin 
(This post was last modified: 06-12-2023, 10:57 PM by SubrataJ.)

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?
Learning Codeigniter 
Reply
#2

You need to load your CustomEvents.php by yourself.

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

(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.
Learning Codeigniter 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB