uEhlO4a
(Y Korotia)
1
i successfully can get json from active records but i need to pass option JSON_UNESCAPED_UNICODE
$r = Books::model()->findAll($c);
echo CJavaScript::jsonEncode($r);
as example above give bad utf-8 output for non english chars
PHP json_encode doesn’t work. so far i see only option to traverse array by my self and make simple objects.
regards
uEhlO4a
(Y Korotia)
2
so far i made a workaround for myself (for current question and this http://www.yiiframework.com/forum/index.php/topic/51053-cdbexpression-in-select-criteria/ ) but that’s workaround…
$c = new CDbCriteria();
$c->select = ['created_date', 'book_guid', 'title', 'year'];
....
$r = Books::model()->findAll($c);
// WORKAROUND -->
$ro = [];
if (is_array($r))
{
foreach ($r as $o) {
$ro_ = new stdClass();
foreach ($c->select as $col) {
$ro_->$col = ($col === 'created_date') ?
(new DateTime($o->$col))->format('Y-m-d') :
$o->$col;
}
$ro[] = $ro_;
}
}
// <----------
echo json_encode($ro, JSON_UNESCAPED_UNICODE);