bcit-ci / CodeIgniter

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
18.27k stars 7.6k forks source link

[Parser] Nested Substitutions not working #6190

Closed Alex-Licea closed 1 year ago

Alex-Licea commented 1 year ago

Hi everybody:

When I try to run a nested substitution with view parser like the example in the docs view_parser.html#nested-substitutions, CI return an exception:

ErrorException Invalid argument supplied for foreach() SYSTEMPATH/View/Parser.php at line 314

I've used CI version 4.2 and 4.3 and the issue is the same.

The only way to make it works is to change the example $data array from the docs example:

$data = [
    'blog_title'   => 'My Blog Title',
    'blog_heading' => 'My Blog Heading',
    'blog_entry'   => [
        'title' => 'Title 1',
        'body'  => 'Body 1',
    ],
];

To this:

$data = [
      'blog_title'   => 'My Blog Title',
      'blog_heading' => 'My Blog Heading',
      'blog_entry'   => [
            [
                  'title' => 'Title 1',
                  'body'  => 'Title 1',
            ],
    ];

The parser can't handle a single level of values in the array, they need to be contained in array to make it work. This behavior is the right one or the docs are outdated?

Thanks for your support.

kenjis commented 1 year ago

This is the repository for CodeIgniter3.

But you are correct. The sample code is not correct. See https://github.com/codeigniter4/CodeIgniter4/pull/7103

Alex-Licea commented 1 year ago

Oh! I'm sorry, but thank you for your support!