I have an UTF-8 table in a MySQL database that contains strings from different languages.
When I display these strings in a grid I get the � symbol in place of the special characters.
My grid is as follows:
and the Yii/PHP code is:
public function actionGrid_data_translations()
{
//
// grid processing and validation
//
function beforeMessageInsert($action){
$sourcemessageid = $_GET['sourcemessageid'];
$action->set_value('SourceMessage_id',$sourcemessageid);
}
//
function beforeMessageUpdate($action){
$sourcemessageid = $_GET['sourcemessageid'];
$action->set_value('SourceMessage_id',$sourcemessageid);
}
//
// grid configuration
//
$sourcemessageid = $_GET['sourcemessageid'];
require_once("dbconnect.php");
$languageoptions = Yii::app()->params['languages'];
$grid = new GridConnector($res, "MySQL");
$config = new GridConfiguration();
$header = Yii::t('translation','Language') . "," . Yii::t('translation','Translation');
$config->setHeader($header);
$config->setInitWidths('150,*');
$config->setColTypes("coro,ed");
$config->setColSorting("str,str");
$grid->set_config($config);
$grid->set_options("language", $languageoptions);
$grid->event->attach("beforeInsert","beforeMessageInsert");
$grid->event->attach("beforeUpdate","beforeMessageUpdate");
$sql = 'SELECT id, language, translation
FROM Message
WHERE SourceMessage_id = ' . $sourcemessageid . '
ORDER BY language ASC';
if ($grid->is_select_mode())
$grid->render_sql($sql,"id","language,translation");
else
$grid->render_table("Message","id","language,translation,SourceMessage_id");
}
}
The strings are displayed correctly in PHP/HTML, they are just wrong in the grid.
Thank you Sam but no, the problem is not solved with your suggestion (when I enclose the javascript code in CDATA tags the entire grid disappear).
There is no XML here, just some PHP code that reads strings from a MySQL table and displays the strings on a page.
When PHP displays the strings directly in HTML, the language characters (accented vowels, etc.) are displayed correctly, when it hands over the strings to the DHTMLX grid they are replaced with the black diamond with a question mark.
Funny enough i one of my grids one column, “language”, built with
$grid->set_options(“language”, $languageoptions);
is displayed correctly, the other one, “translation”, built via
Unfortunately the issue cannot be reconstructed. Please, check your encoding settings.
If issue still occurs - please, provide a demo link where the issue can be reconstructed.
Navigate to the
System/Localisation/Maintain Language option
or to the
System/Localisation/Search Entries option and select the entry: Email (for example) and trigger the action Update Translations
Please, try to open the generated XML in the browser.
You can see the following error:
This page contains the following errors:
error on line 2 at column 57: Encoding error
the Message table, that contains the data, has default character set = utf8 and default collation = utf8_general_ci
if I look at the text with phpMyAdmin or with Navicat I see the text correctly displayed
the text is displayed correctly by PHP in the application (try changing the language and check try to create a new User in the Administration menu and see that the text including accented characters is displayed correctly)
the only problem occurs when the render_table or render_sql functions directly access the Message table; the error occurs in the HTML generated by your code
Please see the attached phpMyAdmin screenshots.
This is a show stopper, if I cannot solve this I won’t be able to use DHTMLX.