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

Phalcon\Application response handling (inaccuracy?)

In docs we have:

echo $application->handle()->getContent();

but I think, the proper be:

$application->handle()->send();

cause handle() returns Phalcon\Http\Response.



98.9k
Accepted
answer

Internally Phalcon\Mvc\Application automatically calls $response->sendHeaders(), so the unique outstanding thing is print the content returned, also both codes you mentioned are valid

edited Oct '14

Thanks for reply!

To avoid open new discussion, I leave my question here.

Creating a custom preconfigured DI container like Phalcon\Di\FactoryDefault. Any suggestions?...

class CustomDi extends Phalcon\Di implements Phalcon\DiInterface
{

    public function __construct()
    {
        parent::__construct();

        $this->setShared('router', function () {
            return new Phalcon\Mvc\Router();
        });

        $this->setShared('view', function () {
            return new Phalcon\Mvc\View();
        });

        $this->setShared('dispatcher', function () {
            return new Phalcon\Mvc\Dispatcher();
        });

        $this->setShared('response', function () {
            return new Phalcon\Http\Response();
        });

        /* ... */
    }

}


98.9k

Your approach is fine, this is another approach:

<?php

class CustomDI extends Phalcon\DI
{

    public function __construct()
    {
        parent::__construct();

        $this->_services = array(       
            new \Phalcon\DI\Service('router', 'Phalcon\Mvc\Router', true),
            new \Phalcon\DI\Service('dispatcher', 'Phalcon\Mvc\Dispatcher', true),  
            //...
        );
    }

}