[RESOLVED] Error in "validate.php" in the "_get_language_mapping()" function

Sorry, I’m new here. I’m starting with the new version of Grocery CRUD Enterprise. I was using the old version (1.6.4) and because of that, I’m encountering various problems in the new one.

I found out that there is an error in the “validate.php” file in the “_get_language_mapping()” function

It happened to me that when I made an error in entering an item in the form, a text was displayed where the error description was in English, even though I had set “Czech”:
$crud->setLanguage('Czech');

I searched for what it could be and found that the translation was missing in the “vendor\vlucas\valitron\lang” directory. So I added the “cs.php” file. But the situation did not change.

So I searched further and found that there is an error in the “_get_language_mapping()” function regarding the evaluation of the “Czech” language.

The problem is that the abbreviation for this language is not “cz”, but “cs” and the incorrect abbreviation “cz” was not in the “if” statement where the check is performed.

So I added the line to the “$languageMapping” field:
'Czech' => 'cs',

And that’s how the error description started to be displayed in Czech :wink:

Hi Johnny,

Can you please fix the mapping for Czech in the “Validate.php” file in the “_get_language_mapping()” function in the next update, as I wrote above?

When I did the update, my fix was overwritten by your incorrect file and I had to fix it again.

Thank you

Hello @PaVal ,

Unfortunately you should have a two steps process to also include it to the language Mapping code. If I add the line:

'Czech' => 'cs',

I am getting an error that the file is not there:

I will try to find a solution for this like having my own dependency to Valitron with the extra language of Czech. It will take a while but I believe it is worth it. With this you wouldn’t mind adding the file again to an update. I will let you know for any updates :slight_smile:

Thank you for your answer.

I sent the translated file “cs.php” to the Valitron creators. But they didn’t answer me.

As I write, I translated the file and put it in the directory “vendor\vlucas\valitron\lang”, so it won’t report an error :wink:

And if it does report an error, at least it’s clear that the file with the translation is missing. And it will certainly not be a problem for others to add it.

Thank you

Hello @PaVal ,

I am glad to inform you that latest Grocery CRUD Enterprise version 3.2.8 includes a custom version of Valitron which includes several other languages including Czech.

Let me know if that works out of the box for you.

Regards
Johnny

Hello Johnny,

thanks, everything works as it should.

Only the “uniqueFields” function still throws an error in English.
I wrote about that error in my post

Regards
Petr

Thank you @PaVal for the feedback. Seems that I have missed this one. Will keep a note to fix it for the next version.

Regards
Johnny

Hello @PaVal ,

I am glad to inform you that latest Grocery CRUD version 3.2.9 is now including translations for unique errors. In order to get the latest upgrade please follow the steps on the wizard: User's Page Login

Let me know if that works for you.

Regards
Johnny

Hello Johnny,

Thanks for the fix.

I upgraded using composer. I updated the contents of the public/vendor/grocery-crud directory.
During the upgrade, CI was also upgraded to version 4.7.2

My application stopped working. It reports the error:

Error: Internal Server Error.
Odpověď serveru:
{
    "title": "ErrorException",
    "type": "ErrorException",
    "code": 500,
    "message": "Trying to access array offset on null",
    "file": "D:\\xampp84\\htdocs\\fw_ci4_fektis\\vendor\\grocery-crud\\enterprise\\src\\GroceryCrud\\Core\\Model.php",
    "line": 358,
    "trace": [
        {
            "file": "D:\\xampp84\\htdocs\\fw_ci4_fektis\\vendor\\grocery-crud\\enterprise\\src\\GroceryCrud\\Core\\Model.php",
            "line": 358,
            "function": "errorHandler",
            "class": "CodeIgniter\\Debug\\Exceptions",
            "type": "->",
            "args": [
                2,
                "Trying to access array offset on null",
                "D:\\xampp84\\htdocs\\fw_ci4_fektis\\vendor\\grocery-crud\\enterprise\\src\\GroceryCrud\\Core\\Model.php",
                358
            ]
        },
        {
            "file": "D:\\xampp84\\htdocs\\fw_ci4_fektis\\vendor\\grocery-crud\\enterprise\\src\\GroceryCrud\\Core\\Model.php",
            "line": 317,
            "function": "_getPrimaryKey",
            "class": "GroceryCrud\\Core\\Model",
            "type": "->",
            "args": [
                "firmy"
            ]
        },
        {
            "file": "D:\\xampp84\\htdocs\\fw_ci4_fektis\\vendor\\grocery-crud\\enterprise\\src\\GroceryCrud\\Core\\State\\InitialState.php",
            "line": 175,
            "function": "getPrimaryKeyField",
            "class": "GroceryCrud\\Core\\Model",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\xampp84\\htdocs\\fw_ci4_fektis\\vendor\\grocery-crud\\enterprise\\src\\GroceryCrud\\Core\\State\\InitialState.php",
            "line": 80,
            "function": "getPrimaryKeyField",
            "class": "GroceryCrud\\Core\\State\\InitialState",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\xampp84\\htdocs\\fw_ci4_fektis\\vendor\\grocery-crud\\enterprise\\src\\GroceryCrud\\Core\\State\\InitialState.php",
            "line": 13,
            "function": "showInitData",
            "class": "GroceryCrud\\Core\\State\\InitialState",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\xampp84\\htdocs\\fw_ci4_fektis\\vendor\\grocery-crud\\enterprise\\src\\GroceryCrud\\Core\\GroceryCrud.php",
            "line": 3447,
            "function": "render",
            "class": "GroceryCrud\\Core\\State\\InitialState",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\xampp84\\htdocs\\fw_ci4_fektis\\app\\Controllers\\Firmy.php",
            "line": 129,
            "function": "render",
            "class": "GroceryCrud\\Core\\GroceryCrud",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\xampp84\\htdocs\\fw_ci4_fektis\\vendor\\codeigniter4\\framework\\system\\CodeIgniter.php",
            "line": 951,
            "function": "index",
            "class": "App\\Controllers\\Firmy",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\xampp84\\htdocs\\fw_ci4_fektis\\vendor\\codeigniter4\\framework\\system\\CodeIgniter.php",
            "line": 497,
            "function": "runController",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->",
            "args": [
                {
                    "helpers": [
                        "url",
                        "html"
                    ],
                    "request": {
                        "protocolVersion": "1.1",
                        "validProtocolVersions": [
                            "1.0",
                            "1.1",
                            "2.0",
                            "3.0"
                        ],
                        "body": null,
                        "headers": {
                            "Host": {
                                "name": "Host",
                                "value": "localhost"
                            },
                            "User-Agent": {
                                "name": "User-Agent",
                                "value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:149.0) Gecko/20100101 Firefox/149.0"
                            },
                            "Accept": {
                                "name": "Accept",
                                "value": "*/*"
                            },
                            "Accept-Language": {
                                "name": "Accept-Language",
                                "value": "cs,sk;q=0.9,en-US;q=0.8,en;q=0.7"
                            },
                            "Accept-Encoding": {
                                "name": "Accept-Encoding",
                                "value": "gzip, deflate, br, zstd"
                            },
                            "Referer": {
                                "name": "Referer",
                                "value": "http://localhost/fw_ci4_fektis/public/firmy"
                            },
                            "Connection": {
                                "name": "Connection",
                                "value": "keep-alive"
                            },
                            "Cookie": {
                                "name": "Cookie",
                                "value": "tracy-session=57939ebb67; _gcl_au=1.1.197102636.1772457641; _ga_SBSPV5DZFM=GS2.1.s1774536291$o26$g1$t1774537310$j54$l0$h0; _ga=GA1.1.50667359.1772457641; _ga_YC7QERE9EW=GS2.1.s1774536291$o26$g1$t1774537688$j60$l0$h0; _ga_TDYCDYRVXV=GS2.1.s1774536291$o26$g1$t1774537688$j60$l0$h0; fontsLoaded=true; _fbp=fb.0.1774536759815.851769213647562642; ci_session_fektis=ddc4b5dbc668d5b863e37899d898b5a9"
                            },
                            "Sec-Fetch-Dest": {
                                "name": "Sec-Fetch-Dest",
                                "value": "empty"
                            },
                            "Sec-Fetch-Mode": {
                                "name": "Sec-Fetch-Mode",
                                "value": "cors"
                            },
                            "Sec-Fetch-Site": {
                                "name": "Sec-Fetch-Site",
                                "value": "same-origin"
                            }
                        },
                        "headerMap": {
                            "host": "Host",
                            "user-agent": "User-Agent",
                            "accept": "Accept",
                            "accept-language": "Accept-Language",
                            "accept-encoding": "Accept-Encoding",
                            "referer": "Referer",
                            "connection": "Connection",
                            "cookie": "Cookie",
                            "sec-fetch-dest": "Sec-Fetch-Dest",
                            "sec-fetch-mode": "Sec-Fetch-Mode",
                            "sec-fetch-site": "Sec-Fetch-Site"
                        },
                        "method": "GET",
                        "uri": {
                            "uriString": null,
                            "baseURL": {
                                "uriString": null,
                                "baseURL": null,
                                "segments": [
                                    "fw_ci4_fektis",
                                    "public"
                                ],
                                "scheme": "http",
                                "user": null,
                                "password": null,
                                "host": "localhost",
                                "port": null,
                                "path": "/fw_ci4_fektis/public/",
                                "fragment": "",
                                "query": [],
                                "defaultPorts": {
                                    "http": 80,
                                    "https": 443,
                                    "ftp": 21,
                                    "sftp": 22
                                },
                                "showPassword": false,
                                "silent": false,
                                "rawQueryString": false
                            },
                            "segments": [
                                "firmy"
                            ],
                            "scheme": "http",
                            "user": null,
                            "password": null,
                            "host": "localhost",
                            "port": null,
                            "path": "/fw_ci4_fektis/public/firmy",
                            "fragment": "",
                            "query": {
                                "action": "initial"
                            },
                            "defaultPorts": {
                                "http": 80,
                                "https": 443,
                                "ftp": 21,
                                "sftp": 22
                            },
                            "showPassword": false,
                            "silent": false,
                            "rawQueryString": false,
                            "basePathWithoutIndexPage": "/fw_ci4_fektis/public/",
                            "indexPage": "",
                            "baseSegments": [
                                "fw_ci4_fektis",
                                "public"
                            ],
                            "routePath": "firmy"
                        },
                        "config": {
                            "baseURL": "http://localhost/fw_ci4_fektis/public/",
                            "allowedHostnames": [],
                            "indexPage": "",
                            "uriProtocol": "REQUEST_URI",
                            "permittedURIChars": "a-z 0-9~%.:_\\-",
                            "defaultLocale": "cs",
                            "negotiateLocale": false,
                            "supportedLocales": [
                                "cs"
                            ],
                            "appTimezone": "Europe/Prague",
                            "charset": "UTF-8",
                            "forceGlobalSecureRequests": false,
                            "proxyIPs": [],
                            "CSPEnabled": false
                        },
                        

The entire text could not be inserted because it is too long and the discussion system reports an error.

Hello @PaVal ,

That’s a very weird issue and it doesn’t seem to be caused by the upgrade. This is pointing to the lines:

        if ($driverName === 'Mysql') {
            $statement = $this->adapter->createStatement('SHOW KEYS FROM `' . $tableName . '` WHERE Key_name = \'PRIMARY\'');

            $result = $statement->execute();

            $primaryKeyData = $result->current();

            $this->primaryKeys[$tableName] = $primaryKeyData['Column_name'];

            return $this->primaryKeys[$tableName];
        }

But nothing really changed. Can you please change if you can get data from your mysql using

SHOW KEYS FROM `your_table_name` WHERE Key_name = 'PRIMARY';

If you can also give a bit more information about your Controller’s function that would also help. Also can you try downgrading to 3.2.8 to see if this is still happening?

Regards
Johnny

Hello Johnny,

I’m sorry. You’re right. I had an error in the test database.

I made a mistake. When I checked the functionality of the command
SHOW KEYS FROM your_table_name WHERE Key_name = ‘PRIMARY’;
I did it on the live version of the database. Here the command returned the correct value. So I wrote here that GC is reporting an error.

When I fixed the test database, everything is fine.

I also tested the “uniqueFields” function and it is reporting the error correctly, according to the set language. In my case in Czech.

Thank you and once again I apologize

Petr

1 Like