I want to put a json encoded result (of ManagementController.php, statisticAction) to the Highchart syntax in view file (stat.phtml) in my Phalcon project. Was originally, in stat.phtml I used:
            ...
            ...
            series: [{
                type: 'pie',
                name: 'Browser share',
                data: []
            }]
        } 
       $.getJSON('data/user_type.php', function(json) {
       options.series[0].data = json;
       chart = new Highcharts.Chart(options);
    });
}); with the php data/user_type.php placed in public folder.
user_type.php:
<?php
$con = mysql_connect("localhost","root","");
if (!$con) {
   die('Could not connect: ' . mysql_error());
}
mysql_select_db("mockup_workspace", $con);
$result = mysql_query("SELECT name_type_user, total FROM v_ntype_user where id_admin=1");
$rows = array();
while($r = mysql_fetch_array($result)) {
$row[0] = $r[0];
$row[1] = $r[1];
array_push($rows,$row);
}
print json_encode($rows, JSON_NUMERIC_CHECK);
mysql_close($con);
?>It works when I load, although the data is static. But it still uses native PHP syntax, so I want to use that logic in Managementcontroller. Then I found the issue that $.getJSON that still need URL json file , while I was using ManagementController. Is there a particular js syntax to replace getJSON? What if I want to bring it from the Controller?
ManagementController.php
<?php
 namespace workspace_mockup_2\Controllers;
 use workspace_mockup_2\Models\VnTypeUser as nTypeUser;
 use Phalcon\Mvc\Controller;
 class ManagementController extends Controller {
  ...
  public function statisticAction() {
    $id_admin = $this->session->get('auth');
    // User Type
    $typeUser = nTypeUser::find('id_admin="' . $id_admin . '"');
    $rows = array();
    while($r = mysql_fetch_array($typeUser)) {
       $row[0] = $r[0];
       $row[1] = $r[1];
    array_push($rows,$row);
    } 
    echo json_encode($rows, JSON_NUMERIC_CHECK);
    $this->view->pick("/frontend/user_management_page/stat");
}I've been looking for a way, such put this in that Controller,
...
$printjson = json_encode($rows, JSON_NUMERIC_CHECK);
$this->view->printjs = $printjson;and put $printjs variable to replace $.getJSON('data/user_type.php', ... in stat.phtml, but it did not work as well.
Please help :(
Thanks.