dregvw1801 2014-09-30 23:12
浏览 50

警告/通知/严格使用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

  • 写回答

1条回答 默认 最新

  • dongrang9300 2014-11-03 22:59
    关注

    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;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起