Skip to content

Commit ef7df32

Browse files
committed
fix: support for assigning extra data for the view() method in controlled cells
1 parent ce7de2d commit ef7df32

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

system/View/Cells/Cell.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ public function setView(string $view)
6565
* current scope and captures the output buffer instead of
6666
* relying on the view service.
6767
*/
68-
final protected function view(?string $view): string
68+
final protected function view(?string $view, array $data = []): string
6969
{
7070
$properties = $this->getPublicProperties();
7171
$properties = $this->includeComputedProperties($properties);
72+
$properties = array_merge($properties, $data);
7273

7374
// If no view is specified, we'll try to guess it based on the class name.
7475
if (empty($view)) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* This file is part of CodeIgniter 4 framework.
5+
*
6+
* (c) CodeIgniter Foundation <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
namespace Tests\Support\View\Cells;
13+
14+
use CodeIgniter\View\Cells\Cell;
15+
16+
class RenderedExtraDataNotice extends Cell
17+
{
18+
public string $message = '4, 8, 15, 16, 23, 42';
19+
20+
public function render(): string
21+
{
22+
return $this->view('notice', ['message' => '42, 23, 16, 15, 8, 4']);
23+
}
24+
}

tests/system/View/ControlledCellTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Tests\Support\View\Cells\GreetingCell;
1919
use Tests\Support\View\Cells\ListerCell;
2020
use Tests\Support\View\Cells\MultiplierCell;
21+
use Tests\Support\View\Cells\RenderedExtraDataNotice;
2122
use Tests\Support\View\Cells\RenderedNotice;
2223
use Tests\Support\View\Cells\SimpleNotice;
2324

@@ -47,6 +48,13 @@ public function testCellThroughRenderMethod()
4748
$this->assertStringContainsString('4, 8, 15, 16, 23, 42', $result);
4849
}
4950

51+
public function testCellThroughRenderMethodWithExtraData()
52+
{
53+
$result = view_cell(RenderedExtraDataNotice::class);
54+
55+
$this->assertStringContainsString('42, 23, 16, 15, 8, 4', $result);
56+
}
57+
5058
public function testCellWithParameters()
5159
{
5260
$result = view_cell(GreetingCell::class, 'greeting=Hi, name=CodeIgniter');

0 commit comments

Comments
 (0)