Welcome Guest, Not a member yet? Register   Sign In
Is a beforeFind on a Model a bad idea?
#4

(06-29-2020, 10:29 PM)tgix Wrote: What am I missing?

/Mattias

It is possible to define custom events. The (static) class method Events::on() allows you to register an event using any name you like.

File: /app/Config/Events.php

PHP Code:
Events::on('before_findAll', [$modelInstance'modelMethod']);  // Call modelMethod on an existing Model instance 


At the appropriate logical spot in your code, something like this

PHP Code:
\CodeIgniter\Events\Events::trigger('before_findAll'$model'modelMethod'); 

You can pass other arguments in trigger if needed.

Events Docs
Reply


Messages In This Thread
Is a beforeFind on a Model a bad idea? - by tgix - 06-29-2020, 10:29 PM
RE: Is a beforeFind on a Model a bad idea? - by dave friend - 06-30-2020, 05:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB