CodeIgniter Forums
Filters:after appears to be ignored - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Filters:after appears to be ignored (/thread-76187.html)

Pages: 1 2


Filters:after appears to be ignored - Gary - 04-20-2020

After reading the CI User Guide (https://codeigniter.com/user_guide/incoming/filters.html#controller-filters),  from my- evidently limited- understanding, AFTER filters are applied to any response from a controller, once it has completed.

As such, I can’t see why they shouldn’t work on a response that is destined for a client-side JavaScript routine (that doesn’t update the client’s page)… after-all, these are also HTTP responses and should be processed in a similar manner to any other response by CodeIgniter\HTTP\ResponseInterface, which all the filters rely on?

What am I missing?


RE: Filters:after appears to be ignored - 5flex - 04-20-2020

To answer your question I need to see the real code, WHAT comes, WHAT goes and WHAT your filter does!


RE: Filters:after appears to be ignored - Gary - 04-20-2020

If you need to see code demonstrating this, a great example is the framework's built-in after filter, 'toolbar'... which has nothing updated in it until the page is refreshed.


RE: Filters:after appears to be ignored - elserra - 04-20-2020

Maybe what you are trying to use are Events?
https://codeigniter.com/user_guide/extending/events.html


RE: Filters:after appears to be ignored - Gary - 04-21-2020

Glossing over the link, Events sound a good possible alternative for me to consider... Thanks for the suggestion Elserra.


RE: Filters:after appears to be ignored - Gary - 04-21-2020

No... although they may be useful for a lot of other things, this (from the User Guide) seems to indicate that they won't work in this case:

"Event Points
...
post_system: Called after the final rendered page is sent to the browser, at the end of system execution after the finalized data is sent to the browser."  <-- there are three of these, this is the only one that is called after the controller is done... by this stage of the game, it's too late.


RE: Filters:after appears to be ignored - kilishan - 04-21-2020

(04-20-2020, 07:21 AM)Gary Wrote: If you need to see code demonstrating this, a great example is the framework's built-in after filter, 'toolbar'... which has nothing updated in it until the page is refreshed.

The DebugToolbar filter does apply changes to the actual output of the script on the way out. It can either add a header or insert javascript. Both of these changes are applied to the body of the response that has been generated and is getting ready to be displayed to the client.

So, there's no reason you can't do this on a Javascript response. What makes you think you cannot? Do you have an example that's not working?


RE: Filters:after appears to be ignored - Gary - 04-21-2020

Thanks for an authoritative clarification on this Kilishan.

I first observed this happening with my own code that was returning only content destined for JavaScript, and then tried to disable as much of my code as possible and observed the toolbar... which appeared to also (consistently) exhibit the same failure-to-update problem as what my code has. Not being up-to-speed on CI, I did suspect my code, but after a lot of fiddling, still couldn't establish a reason why the toolbar was behaving in a similar manner.

Now knowing it should work, I'll have another look, and possibly try to strip out an example to demonstrate how my code has managed to break it.


RE: Filters:after appears to be ignored - kilishan - 04-21-2020

Gary - definitely let us know either way. If you manage to break it we need to get it fixed so an example would be awesome! Otherwise, let us know if we can help troubleshoot.


RE: Filters:after appears to be ignored - Gary - 04-21-2020

Thanks, when I get to the bottom of it, I'll post an update. Chances are good that it's my code.