Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter4 - Event pass by ???
#7

(10-03-2018, 09:32 AM)kilishan Wrote:
(10-03-2018, 06:18 AM)dmyers Wrote: kilishan, thank you for your excellent reply and thank you for all of your hardwork on CodeIgniter 4.
What I was getting at with making events  arguments pass by reference was that instead of a simply triggering something like hooks are today. 
Adding the pass by reference would allow other CodeIgniter 4 developers to use events in more of a universal way to modify arguments sent in without the need to download another "events" class to provide this feature.

DMyers

That's a good idea. Something worth looking into.

Not sure what you're using it for, but would Controller Filters help out.

Kilishan, I was thinking more along the lines of Jamie Rumbelow's old MY_Model code where you would call a before_update or after_update event which could modify it's input.

https://github.com/jamierumbelow/codeign..._Model.php

Another "event" I personally use in my applications is:


PHP Code:
ci('event')->trigger('nav.library.html',$array); 

Which allows other listeners the opportunity to modify the html as needed  


PHP Code:
$this->event->register('nav.library.html',function(&$array){
     if (
$array['user'] == 'nobody') {
        
$array['user'] == 'guest';
     }
  });


This example could probably be rolled into a after filter (not sure how you would get the array)??? but, then how would you dynamically add it to the application/Config/Filters.php file only on pages where needed.

I'm also not sure removeListener(...) works with a Closure? Which you can use as per line 18.


I updated my CodeIgniter 3 Library to add some of your great ideas. You can see it here.

https://github.com/ProjectOrangeBox/oran.../Event.php

I like a few of your ideas


Before I added them I had this. 

https://github.com/ProjectOrangeBox/oran.../Event.php
Reply


Messages In This Thread
CodeIgniter4 - Event pass by ??? - by dmyers - 10-01-2018, 08:41 AM
RE: CodeIgniter4 - Event pass by ??? - by dmyers - 10-02-2018, 06:57 AM
RE: CodeIgniter4 - Event pass by ??? - by falko - 10-02-2018, 01:00 PM
RE: CodeIgniter4 - Event pass by ??? - by dmyers - 10-03-2018, 06:18 AM
RE: CodeIgniter4 - Event pass by ??? - by dmyers - 10-03-2018, 11:43 AM
RE: CodeIgniter4 - Event pass by ??? - by dmyers - 10-03-2018, 12:38 PM
RE: CodeIgniter4 - Event pass by ??? - by dmyers - 10-08-2018, 07:55 AM
RE: CodeIgniter4 - Event pass by ??? - by abrkof - 01-04-2020, 09:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB