We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Attaching to beforeSendResponse event

Hey, what is proper way to attach to 'application:beforeSendResponse' event?

This is what I'm doing, but die("weee"); never gets executed. If I uncomment that another die it will get executed.

And can list of all default phalcon event be found somewhere? I unable to find them from docments

public function setDI(DiInterface $dependencyInjector)
    {
        $this->di = $dependencyInjector;
        $this->registerEvents($dependencyInjector);
        parent::setDI($dependencyInjector); // TODO: Change the autogenerated stub
    }

    public function getDI()
    {
        parent::getDI(); // TODO: Change the autogenerated stub
    }

    private function registerEvents($di) {

        $eventManager = $di->getShared("eventsManager");
        if (!$eventManager) {
            throw new Exception("No events manager");
        }
        //die("this kills");
        $eventManager->attach("application:beforeSendResponse",
            function(Event $event, \Phalcon\Mvc\Application $app, ResponseInterface $response) use($di)  {
                die("weeee");
                /** @var Response $response */
                $response = $di->getShared("response");
                $response->setHeader("flash", json_encode($this->flashes));

            }
        );
    }

Use dispatch:beforeDispatch instead or another one that you need : https://docs.phalcon.io/bs/3.2/dispatcher