viewDirectory in config Paths |
Hi.
In my CI projects, I created an event to detect which theme to show and then update the config('Paths')->viewDirectory variable PHP Code: Events::on('pre_system', static function () I upgraded one of my projects to CI version v4.3.7 and this code stopped working. I debugged and noticed that in the \codeigniter\system\Config\Services.php file, line 483 was replaced with PHP Code: $viewPath = $viewPath ?: (new Paths())->viewDirectory; This change effectively undoes my work in Events because Path is reinitialized. How can I solve this problem? Thanks
Try to extend the view service.
Create your own view service class that extends the built-in view service and overide the method where the view path is determined to use the modified 'viewDirectory' Use your custom view service throughout your application.
Shortcode Κατασκευή Eshop + Δημιουργία Ιστοσελίδων
Athens Greece
The current Config is too liberal and also degrades the performance of CI4.
I recommend all devs not change the Config values at runtime. Then, you will be able to use Config caching in the future to get performance gain. In this case, you can pass $viewPath to Services::renderer(). See https://github.com/codeigniter4/CodeIgni...#L477-L487 Or you could create your own Services::renderer() with the code in the previous version.
Thank you!
I deleted the function in "pre_system" and declared the constant "APPTHEME" in app\Config\Constants.php. Then I rewrote all view() calls to view( APPTHEME .'template.php') in all Controllers. I just have to understand how to manage the possible GET passage of the theme to be displayed temporarily. |
Welcome Guest, Not a member yet? Register Sign In |