CodeIgniter Forums

Full Version: Filters:after appears to be ignored
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
After reading the CI User Guide (https://codeigniter.com/user_guide/incom...er-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?
To answer your question I need to see the real code, WHAT comes, WHAT goes and WHAT your filter does!
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.
Maybe what you are trying to use are Events?
https://codeigniter.com/user_guide/exten...vents.html
Glossing over the link, Events sound a good possible alternative for me to consider... Thanks for the suggestion Elserra.
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.
(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?
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.
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.
Thanks, when I get to the bottom of it, I'll post an update. Chances are good that it's my code.
Pages: 1 2