Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.



85.4k
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();
        });

        /* ... */
    }

}


85.4k

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),  
            //...
        );
    }

}