Hi,
Intresting issue. I'm mounting controllers to a Micro app, setup is a bit more complicated than that but for intents this should explain the issue. When I call $app->after() and if I call send() I get the following exception:
PHP Fatal error: Uncaught Phalcon\Http\Response\Exception: Response was already sent in phalcon/http/response.zep:611
Now this is the strange part, if the method in the controller returns a nonscalar value such as an array I have no exception and when I call getReturnedValue() I get the expected value. If the method returns a string the string is immediately output to the client and I get the exception above.
class IndexController extends \Phalcon\Mvc\Controller
{
public function index()
{
// this will fail if I call send(), sent directly to browser; getReturnedValue() captures this value
return 'test';
// this will succeed only if I call send(), response is not sent and getReturnedValue() captures this value
return ['test' => 'test'];
}
}
// example from index.php
$app->after(function () use ($app) {
echo json_encode($app->getReturnedValue()); // duplicate output if Controller returns a string, string is always output even if I don't call this
});
If I call $app->response->send() while returning a string I get duplicate output and I get an exception. If I don't call send() when returning an array I get no output.