title: Get the JSON encode result from the Controller to View
body: <p>I want to put a json encoded result (of <code>ManagementController.php</code>, <code>statisticAction</code>) to the Highchart syntax in view file (<code>stat.phtml</code>) in my Phalcon project. Was originally, in <code>stat.phtml</code> I used:</p>
  
  <pre><code>            ...
              ...
              series: [{
                  type: 'pie',
                  name: 'Browser share',
                  data: []
              }]
          } 
         $.getJSON('data/user_type.php', function(json) {
         options.series[0].data = json;
         chart = new Highcharts.Chart(options);
      });
  });
  </code></pre>
  
  <p>with the <code>data/user_type.php</code> placed in public folder. </p>
  
  <p><code>user_type.php</code>:</p>
  
  <pre><code>&lt;?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);
  ?&gt;
  </code></pre>
  
  <p>It works when I load, although the data is static. But it still uses <strong>native PHP syntax</strong>, so I want to use that logic in Managementcontroller.  Then I found the issue that <code>$.getJSON</code> that still need URL json file (like <code>data/user_type.php</code>), while I was using ManagementController (myController/actionController).
  So, what if I want to bring it from the Controller?</p>
  
  <p><code>ManagementController.php</code></p>
  
  <pre><code>&lt;?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-&gt;session-&gt;get('auth');
  
      // User Type
      $typeUser = nTypeUser::find('id_admin="' . $id_admin . '"');    
      $rows = array();
      foreach($typeUser as $t) {
          $row[0] = $t-&gt;name_type_user;
          $row[1] = $t-&gt;total;
          array_push($rows,$row);
      }
      echo json_encode($rows, JSON_NUMERIC_CHECK);
      $this-&gt;view-&gt;pick("/frontend/user_management_page/stat");
  }
  </code></pre>
  
  <p>I've been looking for a way, such put this in that Controller,</p>
  
  <pre><code>...
  $printjson = json_encode($rows, JSON_NUMERIC_CHECK);
  $this-&gt;view-&gt;printjs = $printjson;
  </code></pre>
  
  <p>and put <code>$printjs</code> variable to replace <code>$.getJSON('data/user_type.php', ...</code> in <code>stat.phtml</code>, but it did not work as well.
  Please help :(</p>
  
  <p>Thank's..</p>