Here is the deal.
$app->before(function () use ($app) {
$app->response->setHeader("Content-Type", "application/json");
return true;
});
$app->after(function() use ($app){
// This will work for strings. but any array or objects will get a conversion error.
// Also i ahve to set it like this in the controller. $this->response->setContent($stuff);
// I woudl rather return it to the app handler like this return($stuff);
// controller is below
$app->response->getContent();
// the app object here has a return value that is protected. is their a function
// call to retrieve this data?
// below is the var dump of $app in the after call. How can i access this return value?
// so i can add it into the respons via $app->response->setJsonContent($return);
[_returnedValue:protected] => Array
(
[0] => test
[1] => this
[stuff] => Array
(
[0] => really
[1] => good
)
)
$app->response->setJsonContent($app->response->getContent())->send();
});
$test = new Phalcon\Mvc\Micro\Collection();
$test->setHandler('Api\Controllers\TestController', true);
$test->get('/','index');
$app->mount($test);
Controller
<?php
namespace Api\Controllers;
use Phalcon\Mvc\Controller;
class TestController extends Controller
{
public function index()
{
$array = ['test','this','stuff' => ['really','good']];
// this works but then i have to json encode before i set or i get a string conversion error.
// which then kind of negates the re
$this->response->setContent($array);
// this woudl be my prefered method, but i can't seem to get at the object back in the $app->after()
return $array;
}
}