CodeIgniter Forums
codeigniter 4 "need define" in the model this data output->set_header - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: codeigniter 4 "need define" in the model this data output->set_header (/showthread.php?tid=78404)



codeigniter 4 "need define" in the model this data output->set_header - yuma2020 - 01-14-2021

Hello people, as you will see, I am interested in defining in the constructor the following field:
this example is CI3
PHP Code:
$this->output->set_header('Pragma: no-cache'); 
I would appreciate knowing how you can help me resolve this situation because there are currently no repositories and information about it.
I would also add that there is not enough information in the user help panes so that the integration can be applied.
Angel documentation CI4 is missing Information 

is valid this?:
PHP Code:
$this->response->setHeader('Pragma: no-cache'); 



RE: codeigniter 4 "need define" in the model this data output->set_header - iRedds - 01-14-2021

In my opinion. 
If you set headers in the model, then you are doing something wrong.
The controller should be responsible for setting the headers.

Up
PHP Code:
// In controller 
$this->response->setHeader('Pragma''no-cache'); 

//If you still want to do this in the model
Service::response()->setHeader('Pragma''no-cache'); 

https://codeigniter.com/user_guide/outgoing/response.html#setting-headers


RE: codeigniter 4 "need define" in the model this data output->set_header - yuma2020 - 01-16-2021

(01-14-2021, 05:00 PM)iRedds Wrote: In my opinion. 
If you set headers in the model, then you are doing something wrong.
The controller should be responsible for setting the headers.

Up
PHP Code:
// In controller 
$this->response->setHeader('Pragma''no-cache'); 

//If you still want to do this in the model
Service::response()->setHeader('Pragma''no-cache'); 

https://codeigniter.com/user_guide/outgoing/response.html#setting-headers


This would also be valid for calls from controllers or bookries, I simply consult because due to the great diversity there are many forms of calls, but the most appropriate ones would be great.

Example wants to set this from a helper, a library.

PHP Code:
//If you still want to do this in the model
Service::response()->setHeader('Pragma''no-cache'); 

I clarify this code is the one that works apparently in BaseController:
PHP Code:
$this->response = \Config\Services::response()->setHeader('Pragma''no-cache'); 



RE: codeigniter 4 "need define" in the model this data output->set_header - iRedds - 01-17-2021

(01-16-2021, 02:20 PM)yuma2020 Wrote: This would also be valid for calls from controllers or bookries, I simply consult because due to the great diversity there are many forms of calls, but the most appropriate ones would be great.

Example wants to set this from a helper, a library.

PHP Code:
//If you still want to do this in the model
Service::response()->setHeader('Pragma''no-cache'); 

I clarify this code is the one that works apparently in BaseController:
PHP Code:
$this->response = \Config\Services::response()->setHeader('Pragma''no-cache'); 

In any class of your application, you can interact with the Response class by getting an instance of it using \Config\Services::response()
But in a controller, an instance of the Response class can also be accessed through the $this->response property. Because this property gets an instance of the Response class when the controller is initialized.