After further investigation discoverd that this action
public function actionIndex()
{
$data = Marker::find()->all();
return $this->render('index', array('data' => $data ));
}
return the data in this format:
Array ( [0] => app\models\Marker Object ( [_attributes:yii\db\BaseActiveRecord:private] => Array ( [id] => 9 [photo] => foto [description] => Incidente 2 [lat] => 45.619778 [lng] => 13.815197 [city] => 0 [address] => via antonio grego 25 trieste [numero] => [userid] => 1 [created] => 2014-10-17 23:48:44 [modified] => 2014-10-19 19:44:21 [status_id] => 1 ) [_oldAttributes:yii\db\BaseActiveRecord:private] => Array ( [id] => 9 [photo] => foto [description] => Incidente 2 [lat] => 45.619778 [lng] => 13.815197 [city] => 0 [address] => via antonio grego 25 trieste [numero] => [userid] => 1 [created] => 2014-10-17 23:48:44 [modified] => 2014-10-19 19:44:21 [status_id] => 1 ) [_related:yii\db\BaseActiveRecord:private] => Array ( ) [_errors:yii\base\Model:private] => [_validators:yii\base\Model:private] => [_scenario:yii\base\Model:private] => default - etc. -
Instead I would need this type of data:
[{"id":"9","0":"9","photo":"foto","1":"foto","description":"Incidente 2","2":"Incidente 2","lat":"45.619778","3":"45.619778","lng":"13.815197","4":"13.815197","city":"0","5":"0","address":"via antonio grego 25 trieste","6":"via antonio grego 25 trieste","numero":"","7":"","userid":"1","8":"1","created":"2014-10-17 23:48:44","9":"2014-10-17 23:48:44","modified":"2014-10-19 19:44:21","10":"2014-10-19 19:44:21","status_id":"1","11":"1"},{"id":"10","0":"10","photo":"ggg","1":"ggg","description":"Lavori in corso","2": - etc. -
And these data are derived from a direct sql call to the db (and json conversion)
$sth = $db->query("SELECT * FROM marker");
$locations = $sth->fetchAll();
echo json_encode( $locations );
It is clear that I don’t know how to right query the database using a controller action to meet up the data in this format. Is there someone can help me, please ?