setHeader not available in Responseinterface |
Hi,
in the BaseController there is a response property i want wo use. Like in the documentation we can use $this->response->setHeader, but there is no function setHeader. How can i set a header? This is not working: https://codeigniter4.github.io/userguide...ng-headers
Yes the Response class, but the interface has not the needed methods. Why is it in the documentation if it is not working?
In the BaseController $response is available. \Config\Service::response()->setHeader() is working, but if we have the response property available this makes no sense. What is the right way? Why are the needed methods not in the interface?
$this->response refers to the same instance class as \Config\Service::response()
So if \Config\Service::response()->setHeader() works, then $this->request->setHeader() will work. I don't know why these methods are not in the interface. That is the way.
I'm not sure.
But Responseinterface will be PSR-7's ResponseInterface in the future and it does not have setHeader() method. So setHeader() will not be added. The sample code works, because CI injects a Response object in $this->response.
(06-29-2022, 03:35 PM)kenjis Wrote: The sample code works, because CI injects a Response object in $this->response. I disagree, this is not true. The code ist not working and the documentation should be adjusted. CI injects the interface and the interface has no method setHeader. \Config\Service::response()->setHeader() is working (I think this is unnecessary, because we have an response object available, but with missing setHeader()) $this->response->setHeader() is not working The documentation at https://codeigniter4.github.io/userguide...ng-headers should show an alternative way. I think the interfaces with the missing methods makes simple things more complicated.
Show your code in the BaseController that is not working.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
My IDE shows me this message:
https://ibb.co/0ZBtCJg but in the browser it is working. What is the reason? The interface does not have this method |
Welcome Guest, Not a member yet? Register Sign In |