Add change view folder for VIew |
I would like to add a method to change the View->setViewPath($path) template catalog.
Because you can't change the folder for the shared class: Services::renderer(...) The modified object cannot be returned in the filter. Is this function needed in the framework? PHP Code: // Before (default) $theme = 'standart'
Simple CI 4 project for beginners codeigniter-expenses
Why do you need to change the view path dynamically?
You can set the path if you call Services::renderer($viewPath).
As standard, change the theme folder. The theme is stored in the database.
1. The change in BaseController is not global. 2. It is unwise to create each View anew. I consider it normal to change in the process
Simple CI 4 project for beginners codeigniter-expenses
If you don't need to change the path in a request more than once,
the following code works. PHP Code: <?php
I haven't checked it yet, but what happens when this instance is created earlier? For example, after view(), view_cell(), ..?
Or do you need to have a template engine in the services: User Manager, Sender, Auth...? Initialization will be called earlier and may not be the one that is needed. UPD: This method is not suitable for calling in filters. As well as the creation in the constructor. The folder does not change, I probably have initialization of services somewhere before
Simple CI 4 project for beginners codeigniter-expenses
You must call Services::renderer($viewPath) before calling view() in anywhere.
The first instance created by Services is shared.
I know. It's not working right now. Somewhere initialization happens earlier. Therefore, changing the folder on the fly would be a good solution.
Simple CI 4 project for beginners codeigniter-expenses
If you want to use it in filters, why don't you call Services::renderer($viewPath) in pre_system Event?
Do you think this is right? If you need to change it again later in the code?
Simple CI 4 project for beginners codeigniter-expenses
I don't see why you need to change the path dynamically.
Does the theme change in one request? Why don't you set the theme's view path at first? |
Welcome Guest, Not a member yet? Register Sign In |