zzarbi
zzarbi

Reputation: 1852

Warning/Notice/Strict with Phalcon

I'm using Phalcon 1.3.3 and PHP 5.4. In my controller i have something like:

public function indexAction() {
    $this->response->setContentType('application/json');
    $data = json_encode(['some data']);

    $this->response->setContent($data);
    return $this->response->send();
}

If I put an "echo" in this action, I can't see it anywhere and i think this is realted to the fact that Phalcon use buffer output (It is possible to get Phalcon\Mvc\View rendered output in variable?)

But that's not really my problem, my problem is that if I have warnings/notice about missing variable, or undeclared constant or using deprecated methods, I can't see those on the rendered page. I can see them in the logs but not the page itself which is a bit annoying when developing. In production obviously it's not a problem.

PS: I have "display_errors" and "display_startup_errors" set to 1 and if I put an exist before rendering the page I see all the warnings

Upvotes: 0

Views: 550

Answers (1)

Lukas Liesis
Lukas Liesis

Reputation: 26403

I use this to return json:

    $expireDate = new \DateTime();

    $this->response->setHeader('Access-Control-Allow-Origin', '*');
    $this->response->setContentType('application/json', 'UTF-8');
    $this->response->setExpires($expireDate);
    $this->response->setHeader('Cache-Control', 'private, max-age=0, must-revalidate');
    $this->response->sendHeaders();
    echo json_encode(array('response' => $response, 'error' => $this->api_error));

and in index.php

/**
 * Handle the request
 */
$application = new \Phalcon\Mvc\Application($di);
//disable view service in general
$application->useImplicitView(false);

if you want to disable view rendering just for some places, you can use in controller:

$this->view->disable(); 
echo $data;

Upvotes: 1

Related Questions