You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tests/system/View/ViewTest.php
+78-5Lines changed: 78 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@
17
17
useCodeIgniter\Exceptions\RuntimeException;
18
18
useCodeIgniter\Test\CIUnitTestCase;
19
19
useCodeIgniter\View\Exceptions\ViewException;
20
-
useConfig;
20
+
useConfig\ViewasViewConfig;
21
21
usePHPUnit\Framework\Attributes\Group;
22
22
23
23
/**
@@ -28,15 +28,16 @@ final class ViewTest extends CIUnitTestCase
28
28
{
29
29
privateFileLocatorInterface$loader;
30
30
privatestring$viewsDir;
31
-
privateConfig\View$config;
31
+
privateViewConfig$config;
32
32
33
33
protectedfunctionsetUp(): void
34
34
{
35
35
parent::setUp();
36
36
37
-
$this->loader = service('locator');
38
-
$this->viewsDir = __DIR__ . '/Views';
39
-
$this->config = newConfig\View();
37
+
$this->loader = service('locator');
38
+
$this->viewsDir = __DIR__ . '/Views';
39
+
$this->config = newViewConfig();
40
+
$this->config->appOverridesFolder = '';
40
41
}
41
42
42
43
publicfunctiontestSetVarStoresData(): void
@@ -413,4 +414,76 @@ public function testViewExcerpt(): void
413
414
$this->assertSame('CodeIgniter is a PHP full-stack web framework...', $view->excerpt('CodeIgniter is a PHP full-stack web framework that is light, fast, flexible and secure.', 48));
414
415
$this->assertSame('CodeIgniter - это полнофункциональный веб-фреймворк...', $view->excerpt('CodeIgniter - это полнофункциональный веб-фреймворк на PHP, который является легким, быстрым, гибким и безопасным.', 54));
Copy file name to clipboardExpand all lines: user_guide_src/source/changelogs/v4.7.0.rst
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -191,6 +191,8 @@ Libraries
191
191
- **ResponseTrait:** Added ``paginate``` method to simplify paginated API responses. See :ref:`ResponseTrait::paginate() <api_response_trait_paginate>` for details.
192
192
- **Time:** added methods ``Time::addCalendarMonths()`` and ``Time::subCalendarMonths()``
193
193
- **Time:** Added ``Time::isPast()`` and ``Time::isFuture()`` convenience methods. See :ref:`isPast <time-comparing-two-times-isPast>` and :ref:`isFuture <time-comparing-two-times-isFuture>` for details.
194
+
- **View:** Added the ability to override namespaced views (e.g., from modules/packages) by placing a matching file structure within the **app/Views/overrides** directory. See :ref:`Overriding Namespaced Views <views-overriding-namespaced-views>` for details.
Copy file name to clipboardExpand all lines: user_guide_src/source/outgoing/views.rst
+47Lines changed: 47 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -104,6 +104,53 @@ example, you could load the **blog_view.php** file from **example/blog/Views** b
104
104
105
105
.. literalinclude:: views/005.php
106
106
107
+
.. _views-overriding-namespaced-views:
108
+
109
+
Overriding Namespaced Views
110
+
===========================
111
+
112
+
.. versionadded:: 4.7.0
113
+
114
+
You can override a namespaced view by creating a matching directory structure within your application's **app/Views** directory.
115
+
This allows you to customize the output of modules or packages without modifying their core source code.
116
+
117
+
Configuration
118
+
-------------
119
+
120
+
By default, overrides are looked for in the **app/Views/overrides** directory. You can configure this location via the ``$appOverridesFolder`` property in **app/Config/View.php**:
121
+
122
+
.. code-block:: php
123
+
124
+
public string $appOverridesFolder = 'overrides';
125
+
126
+
If you prefer to map namespaces directly to the root of **app/Views** (without a subdirectory), you can set this value to an empty string (``''``).
127
+
128
+
Example
129
+
-------
130
+
131
+
Assume you have a module named **Blog** with the namespace ``Example\Blog``. The original view file is located at:
132
+
133
+
.. code-block:: text
134
+
135
+
/modules
136
+
└── Example
137
+
└── Blog
138
+
└── Views
139
+
└── blog_view.php
140
+
141
+
To override this view (using the default configuration), create a file at the matching path within **app/Views/overrides**:
142
+
143
+
.. code-block:: text
144
+
145
+
/app
146
+
└── Views
147
+
└── overrides <-- Configured $appOverridesFolder
148
+
└── Example <-- Matches the first part of namespace
149
+
└── Blog <-- Matches the second part of namespace
150
+
└── blog_view.php <-- Your custom view
151
+
152
+
Now, when you call ``view('Example\Blog\blog_view')``, CodeIgniter will automatically load your custom view from **app/Views/overrides/Example/Blog/blog_view.php** instead of the original module view file.
0 commit comments