Bug (?) by using ResponseTrait within a filter |
10-14-2022, 10:02 AM
(This post was last modified: 10-15-2022, 06:14 AM by groovebird. Edit Reason: It is not a bug - adjust title )
Hi,
i want to use the ResponseTrait in a filter but i get the following error: Undefined property: App\\Filters\\BackendAuth::$response" This is my filter: PHP Code: namespace App\Filters;
ResponseTrait is not intended to use with filters.
It is for controllers.
(10-14-2022, 04:51 PM)kenjis Wrote: ResponseTrait is not intended to use with filters. Ok, thank you. I want to check globally in my controller if access is allowed or not. Thats why i tried at first to use the Response Trait in the constructor of my controller but this is not working. Is it right, that some things, if used in the constructor, not work as expected? The Response Trait is one thing and the setHeader method does not set the header if i use it in the constructor. (10-15-2022, 04:16 AM)groovebird Wrote: Is it right, that some things, if used in the constructor, not work as expected? It does not work as expected. Because the constructor cannot return a Response object. Controller should return a Response object. And in a filter, what you do is just return the Response object that you want. See https://codeigniter4.github.io/CodeIgnit...ponse.html
(10-15-2022, 05:37 AM)kenjis Wrote: It does not work as expected. @kenjis thanks for the clarification. Then the correct way is to use a filter for things (not only the access check) i want to execute every time the controller is executed? |
Welcome Guest, Not a member yet? Register Sign In |