Welcome Guest, Not a member yet? Register   Sign In
How to set global layout data?
#3

Thank for the reply.
I looked closer at how templates are rendered in the View class of CI4 and decided not to use them at all. Instead I just render views.
In order to pass common data to views like header or footer I added a simple static variable in BaseController class. The variable is just an associative array. It contains keys and values.
PHP Code:
public static $globals = []; 

If I need to add some global data somewhere, like in the BaseController, I just create a key and assign a value.
PHP Code:
self::$globals['key'] = 'value'

Then in my view:
PHP Code:
esc(\App\Controller\BaseController::$globals['key']); 
It is ugly quick fix, but dealing with the mess made with templates in CI4 is even worse.
Reply


Messages In This Thread
How to set global layout data? - by forumz - 10-27-2021, 05:32 PM
RE: How to set global layout data? - by InsiteFX - 10-28-2021, 01:51 AM
RE: How to set global layout data? - by forumz - 10-28-2021, 12:08 PM



Theme © iAndrew 2016 - Forum software by © MyBB