diff --git a/system/View/Table.php b/system/View/Table.php index df0fbebd2bc5..5e241f11fefc 100644 --- a/system/View/Table.php +++ b/system/View/Table.php @@ -265,7 +265,7 @@ protected function _prepArgs(array $args) // If there is no $args[0], skip this and treat as an associative array // This can happen if there is only a single key, for example this is passed to table->generate // array(array('foo'=>'bar')) - if (isset($args[0]) && count($args) === 1 && is_array($args[0]) && ! isset($args[0]['data'])) { + if (isset($args[0]) && count($args) === 1 && is_array($args[0])) { $args = $args[0]; } diff --git a/tests/system/View/TableTest.php b/tests/system/View/TableTest.php index 3c607930616a..f4d7f4056f2d 100644 --- a/tests/system/View/TableTest.php +++ b/tests/system/View/TableTest.php @@ -816,6 +816,64 @@ public static function orderedColumnUsecases(): iterable ], ]; } + + /** + * @see https://github.com/codeigniter4/CodeIgniter4/issues/8051 + */ + public function testGenerateTableWithHeadingContainFieldNamedData(): void + { + $table = new Table(); + $table->setHeading([ + 'codigo' => 'Codigo Orçamento', + 'data' => 'Data do Orçamento', + 'tipo_desconto' => 'Tipo de Desconto', + 'valor_desconto' => 'Valor do Desconto', + ])->setSyncRowsWithHeading(true); + + $sampleData = [ + [ + 'id' => 1, + 'id_cliente' => 1, + 'codigo' => 'codigo1', + 'data' => '2023-10-16 21:53:25', + 'tipo_desconto' => 'NENHUM', + 'valor_desconto' => '', + 'created_at' => '2023-10-16 21:53:25', + 'updated_at' => '2023-10-16 21:53:25', + 'deleted_at' => '', + ], + [ + 'id' => 2, + 'id_cliente' => 2, + 'codigo' => 'codigo2', + 'data' => '2023-10-16 21:53:25', + 'tipo_desconto' => 'REAL', + 'valor_desconto' => 10.00, + 'created_at' => '2023-10-16 21:53:25', + 'updated_at' => '2023-10-16 21:53:25', + 'deleted_at' => '', + ], + [ + 'id' => 3, + 'id_cliente' => 3, + 'codigo' => 'codigo3', + 'data' => '2023-10-16 21:53:25', + 'tipo_desconto' => 'PERCENTUAL', + 'valor_desconto' => 10.00, + 'created_at' => '2023-10-16 21:53:25', + 'updated_at' => '2023-10-16 21:53:25', + 'deleted_at' => '', + ], + ]; + + $generated = $table->generate($sampleData); + + $this->assertStringContainsString('