Skip to content

Commit 004814c

Browse files
committed
docs: document namespaced view overriding
1 parent fcd760c commit 004814c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

user_guide_src/source/changelogs/v4.7.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ Libraries
125125
- **Image:** Added ``ImageMagickHandler::clearMetadata()`` method to remove image metadata for privacy protection.
126126
- **ResponseTrait:** Added ``paginate``` method to simplify paginated API responses. See :ref:`ResponseTrait::paginate() <api_response_trait_paginate>` for details.
127127
- **Time:** added methods ``Time::addCalendarMonths()`` and ``Time::subCalendarMonths()``
128+
- **View:** Added the ability to override namespaced views (e.g., from modules) by placing a matching file structure within the **app/Views** directory. See :ref:`Overriding Namespaced Views <views-overriding-namespaced-views>` for details.
129+
128130

129131
Commands
130132
========

user_guide_src/source/outgoing/views.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,38 @@ example, you could load the **blog_view.php** file from **example/blog/Views** b
104104

105105
.. literalinclude:: views/005.php
106106

107+
.. _views-overriding-namespaced-views:
108+
Overriding Namespaced Views
109+
===========================
110+
111+
.. versionadded:: 4.7.0
112+
Added the ability to override namespaced views via the **app/Views** directory.
113+
114+
You can override a namespaced view by creating a matching directory structure within your main **app/Views** directory.
115+
This allows you to customize the output of modules or packages without modifying their source code.
116+
117+
For example, assume you have a module named Blog with the namespace ``Example\Blog``. The original view file is located at:
118+
119+
.. code-block:: text
120+
121+
/modules
122+
└── Example
123+
└── Blog
124+
└── Views
125+
└── blog_view.php
126+
127+
To override this view, create a file at the matching path within your application's Views directory:
128+
129+
.. code-block:: text
130+
131+
/app
132+
└── Views
133+
└── Example <-- Matches the first part of namespace
134+
└── Blog <-- Matches the second part of namespace
135+
└── blog_view.php <-- Your custom view
136+
137+
Now, when you call ``view('Example\Blog\blog_view')``, CodeIgniter will automatically load your custom view from **app/Views/Example/Blog/blog_view.php** instead of the original view file.
138+
107139
.. _caching-views:
108140

109141
Caching Views

0 commit comments

Comments
 (0)