post by rrit on Jun 26, 2023

Hello @johnny ,

It works pretty with PHP 7.4, but don’t works with PHP 8.1:
the two fields

$crud->setRelationNtoN(
            'suppliers',
            'product_suppliers',
            'suppliers',
            'product_id',
            'supplier_id',
            '{n_1} {lf_nr}-{connection_id}'
        );
$crud->setRelationNtoN(
            'groups',
            'product_groups',
            'groups',
            'product_id',
            'group_id',
            '{bez} {wa_grp}-{connection_id}'
        );

are populated on product create with supplier_id and group_id (the user see in the select field supplier name and group name).
After save if I call the view form for the product, I can see the saved supplier and group (with both PHP 7.4 and 8.1 versions):


if I call edit form, the supplier and group names in select fields are invisible (PHP 8.1):

There are no error messages in CI- nor PHP-Log.
The supplier_id and group_id (hidden values) will be send to server with the save-button.

I can pick up the new supplier & group from select list, but it will overwrite the old saved data that I’m not able to see.

The edit form works perfect with PHP 7.4:

How to fix? I need PHP 8.1 for another parts of my project…

post by rrit on Jun 29, 2023

Two Videos, the Bug can be reproduced any time:

  1. PHP7.4 - all OK as expected, started with
./spark serve
CodeIgniter v4.3.4 Command Line Tool - Server Time: 2023-06-29 14:15:59 UTC+02:00
CodeIgniter development server started on http://localhost:8080
[Thu Jun 29 14:15:59 2023] PHP 7.4.33 Development Server (http://localhost:8080) started
  1. PHP8.1- Problem, started with
./spark serve --php /usr/bin/php8.1
CodeIgniter v4.3.4 Command Line Tool - Server Time: 2023-06-29 14:36:56 UTC+02:00
CodeIgniter development server started on http://localhost:8080
[Thu Jun 29 14:36:56 2023] PHP 8.1.20 Development Server (http://localhost:8080) started`

The same behavior is on the production Server (Apache Webserver, PHP8.1 / PHP 7.4) :pensive:

post by rrit on Jul 3, 2023

Hello @johnny,

I think I have found the cause of error.

It’s a JSON Response to front-end from $crud->render()

with PHP 7.4:
...,"suppliers":["74"],"groups":["5"],...

string indexes, names found and shown

with PHP 8.1:
...,"suppliers":[74],"groups":[5],...

integer indexes, names are not found

Can you fix this please?

Best regards
Ruslan

post by rrit on Jul 3, 2023

The Problem is in the different behavior of the json_encode()-function in PHP7.4 and PHP8.1.

If I change in EditFormState::render() (line 108) the

$render->output = json_encode($output);
to
$render->output = json_encode($output, JSON_NUMERIC_CHECK);

then the output seems equal in any PHP version, but front-end presentation of ALL select fields is wrong(empty).

post by johnny on Jul 4, 2023

Hello @rrit and thank you for the detailed bug report,

I can reproduce the issue and I will try to fix that the soonest possible. I will try to have a new release this week.

I will keep you posted.

Regards
Johnny

post by johnny on Jul 8, 2023

Hello @rrit ,

The issue is now fixed on 3.0.9 version. Please let me know if it works also for you.

Regards
Johnny

post by rrit on Jul 10, 2023

1 / 7
Jun 2023