Welcome Guest, Not a member yet? Register   Sign In
Setting response outside controller
#1

In CI3 I usually use something like:
PHP Code:
$ci =& get_instance();
$ci->$output->set_output($response)->_display();
exit; 

How to do it in CI4?
Reply
#2

From: CodeIgniter User Guide - Accessing the Request

If you are not within a controller, but still need access to the application’s Request object, you can get a copy of it through the Services class:


PHP Code:
$request = \Config\Services::request(); 

It’s preferable, though, to pass the request in as a dependency if the class is anything other than the controller, where you can save it as a class property:
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB