feat: allow overriding namespaced views via app/Views directory#9860
feat: allow overriding namespaced views via app/Views directory#9860michalsn merged 10 commits intocodeigniter4:4.7from
app/Views directory#9860Conversation
|
It looks good for modules. Questions:
|
CodeIgniter will look for: app/Views/Example/Blog/Views/blog_view.php. If the user explicitly includes
Yes, if a file exists in the matching path within app/Views, it will take precedence over the module's file. |
michalsn
left a comment
There was a problem hiding this comment.
I'm not sure whether we should add a configuration option for this, allowing users to disable the functionality. The chances of this breaking existing code are small, though.
As for the difference between view('Example\Blog\blog_view') and view('Example\Blog\Views\blog_view'), this is a module developer's decision. We should not attempt to manipulate or normalize it, as that could lead to issues when developers choose more complex or non-standard folder structures.
We could technically add a flag to app\Config\View.php to toggle this behavior. However, I personally believe it is unnecessary. Since this logic only triggers when a user deliberately creates a matching directory structure in app/Views corresponding to a specific namespace, the probability of an accidental collision is extremely low.
Exactly. The current implementation intentionally avoids any magic stripping of segments like Views. It performs a direct 1-to-1 mapping of the namespace string to the directory path. This ensures predictable behavior regardless of how the module developer structured their views. |
|
I've been trying modularity for a long time and working with templates is causing problems. I would not like to develop templates for Bootstrap when the global project theme is written in TailwindCSS. This feature seems to solve this problem - I don't need to create templates for the module. |
062dc7d to
f929715
Compare
Co-authored-by: Michal Sniatala <michal@sniatala.pl>
Co-authored-by: Michal Sniatala <michal@sniatala.pl>
Co-authored-by: Michal Sniatala <michal@sniatala.pl>
f929715 to
b55768a
Compare
|
Thank you @datamweb |
Description
This PR adds the ability to override namespaced views (typically from modules or packages) by placing a matching file structure within the application's local app/Views directory.
See : https://forum.codeigniter.com/showthread.php?tid=93684&pid=427797#pid427797
Checklist: