CodeIgniter Forums
Using Controller Filters to add data to Views - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Using Controller Filters to add data to Views (/thread-77223.html)



Using Controller Filters to add data to Views - myo - 08-04-2020

Hi,

I read about Controller Filters but still unsure how to send data to Views using AFTER filter as per documentation AFTER Filter "Allows to inspect and modify the response"

In controllers we can send data to views using  "return view('My_view', $this->data);" 
How do we send or iterate through the response object using After Filters? Can we send data to views as well?

Regards


RE: Using Controller Filters to add data to Views - InsiteFX - 08-04-2020

Filters are for Controllers not views. What you want to look at is View Cells.


RE: Using Controller Filters to add data to Views - myo - 08-04-2020

(08-04-2020, 03:59 AM)InsiteFX Wrote: Filters are for Controllers not views. What you want to look at is View Cells.

Documentation says about AFTER filters: "This does allow you to modify the final output, or simply do something with the final output."

How to access the response object & do something for example: remove bad words & include a view cell?


RE: Using Controller Filters to add data to Views - jreklund - 08-04-2020

What you get are a Response object, and you can do everything that's available here:
https://codeigniter.com/user_guide/outgoing/response.html

And for bad words:
$response->getBody();
// do stuff
$response->setBody($clean);

Don't think you can inject a view cell somewhere. Haven't tested it thought.