![]() |
Hello,
I have a filter that runs before all requests and performs some various checks in a database prior to executing the request. If a specific condition is met, I want to render a certain view and stop the action of the controller. In the documentation it says "...You can easily do this by returning [b]any non-empty[/b] result" When I put: Code: return view('myviewname'); it doesn't load that view and instead just keeps processing the request through the targeted controller. The only way I've found to get that view to render within the filter is to put: Code: echo view('myviewname'); Am I interpreting the documentation incorrectly? Or is this a bug? Shouldn't returning a view stop the action of the requested controller?
Return Response object.
(02-15-2022, 05:06 PM)derekairdrie Wrote: Am I interpreting the documentation incorrectly? Or is this a bug? Shouldn't returning a view stop the action of the requested controller? The documentation may be difficult to understand or misleading. Returning non-empty result just stops filter executions, not controller execution. You don't have to use this tricky feature.
You can return an instance of the Response class.
PHP Code: return \Config\Services::response()->setBody(view(....)); @kenjis I think that in 5.x it is necessary to lay the ability to process the returned result of the filter as a string as a response.
@iRedds I would like to replace the current filter with PSR-15 in 5.x, and I don't know it is possible or not that the customization that you say.
(02-16-2022, 01:15 AM)iRedds Wrote: You can return an instance of the Response class. This is exactly what I needed, thanks! |
Welcome Guest, Not a member yet? Register Sign In |