Skip to content

Commit fca9f82

Browse files
committed
adds viewdataprovider
1 parent 1751264 commit fca9f82

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/Mvc/Controllers/Base.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,33 @@ public function renderMarkdown( HttpResponseStatus $responseCode, array $data =
8383

8484
/**
8585
* Inject URL helpers and other view helpers into view data.
86-
*
86+
*
87+
* This method:
88+
* 1. Merges global view data from ViewDataProvider (if registered)
89+
* 2. Injects UrlHelper for route generation (if router available)
90+
* 3. Controller-specific data takes precedence over global data
91+
*
8792
* @param array $data The view data array
88-
* @return array Data array with helpers injected
93+
* @return array Data array with helpers and global data injected
8994
*/
9095
protected function injectHelpers( array $data ): array
9196
{
97+
$registry = \Neuron\Patterns\Registry::getInstance();
98+
99+
// Merge global view data from ViewDataProvider if available
100+
$viewDataProvider = $registry->get( 'ViewDataProvider' );
101+
if( $viewDataProvider instanceof \Neuron\Mvc\Views\ViewDataProvider )
102+
{
103+
// Global data first, then controller data (controller data wins)
104+
$data = array_merge( $viewDataProvider->all(), $data );
105+
}
106+
92107
// Only inject UrlHelper if router is available
93108
if( isset( $this->_router ) )
94109
{
95110
$data['urlHelper'] = new UrlHelper( $this->_router );
96111
}
112+
97113
return $data;
98114
}
99115

versionlog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## 0.8.12
2+
* Added ViewDataProvider interface for injecting data into views globally.
23

34
## 0.8.11 2025-11-12
45
* Renamed config.yaml to neuron.yaml

0 commit comments

Comments
 (0)