• 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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