drxt70655 2013-11-03 00:41
浏览 61

Phalcon PHP - 创建“postDispatch”插件来处理响应

Can someone point me in the proper direction for creating a zend-mvc style postDispatch plugin?

I tried using afterDispatchLoop() but I need a way to access the current response. The goal is to do some sort of filter on the Response (rendered layout + view) , and then reset the response with the new filtered text.

I also tried using afterRender() and beforeRender() but had no luck because the response that I get from the dependency injector is empty.

Please help if you know how to achieve this! Thank you!


UPDATE

I have got it working using the View event (afterRender). This event passes an instance of the Phalcon MVC view, where you can subsequently modify the body of the entire view but calling $view->getContent() + manipulation, followed by $view->setContent().

I am used to working with HTTP Response objects like in Zend. Is there a better way to achieve this sort of response manipulation in Phalcon?

  • 写回答

1条回答 默认 最新

  • dongshicuo4844 2014-02-07 12:44
    关注

    if you get empty results from services in dependency injector, you can enable php singleton design pattern for services with just adding "true" flag like this:

    $di->set('view', function() use($config) {
        $view = new \Phalcon\Mvc\View();
        $view->setViewsDir($config->application->viewsDir);
        $view->registerEngines(array(
            ".volt" => 'volt',
        ));
        return $view;
    }, true);
    

    $di->set('service', function(){}, SINGLETON_TRUE_OR_FALSE)

    more info here: http://docs.phalconphp.com/en/latest/reference/di.html#shared-services

    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题