CodeIgniter Forums
CodeIgniter4 - Event listner - Printable Version

+- CodeIgniter Forums (
+-- Forum: CodeIgniter 4 (
+--- Forum: CodeIgniter 4 Discussion (
+--- Thread: CodeIgniter4 - Event listner (/showthread.php?tid=71755)

Pages: 1 2

RE: CodeIgniter4 - Event listner - unodepiera - 09-29-2018

(09-29-2018, 12:38 PM)happyape Wrote:
(09-29-2018, 11:47 AM)unodepiera Wrote:
(09-19-2018, 03:21 AM)happyape Wrote: I am just trying to understand if CI4 events ( are meant to function similar way as of Laravel (

I am not comparing two frameworks but instead trying to understand how to achieve it in CI4.

My requirement is to be able to, say, take some actions after a user has registered successfully. I am assuming I'd dispatch an "user_registered_successfully" event and there would be listener registered to take some action.

Fast example:

PHP Code:
Events::on('userRegistered', function (User $user) {
//send an email to registered user

PHP Code:
$userModel = new User;
$userEntity = new \App\Entities\User;
$postEscapedData esc($this->request->getRawInput());

Great! I'll give it a go. Thank you.

Another way directly from CodeIgniter model events:

PHP Code:
protected $afterInsert = ['sendEmailToUser'];

protected function 
sendEmailToUser(array $data)
   //TODO send email to new user

RE: CodeIgniter4 - Event listner - abrkof - 01-04-2020

But if can auto load this event in the event name post_controller_constructor? how can auto load all my logic in for example file.php whit a class and a function, evaluate and running a specific action?

Structure of my logic:

Directory = Hooks
Class = MyAccess
Function = evaluate

The exposed structure is an example, for the purposes of the case, it contains all the logic of user login evaluation, this was developed in CI3, it is already configured with the requirements according to the CI4 standard, so what I need is to know how auto load this class as an event in CI4 just like they are loaded in CI3, I have read all the official documentation about it, but I can't find a solution or example to use it.

RE: CodeIgniter4 - Event listner - InsiteFX - 01-05-2020

You need to read this:

CodeIgniter 4 User Guide - Events