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

No echo output in browser?

Hello,

I am new to phalcon and probably going to ask allot of questions here.

I have used phalcon devtools to create a project skelleton.

And did some testing in the indexAction(){} from the indexController.

my index controller looks like:

 class IndexController extends ControllerBase

{

    public function indexAction()

    {

        echo "OUUUUUTPUUUUUUUUUUUUUUUT";

    }

}

and index.volt looks like:

 <!DOCTYPE html>

<html>

    <head>

        <title>Phalcon PHP Framework</title>

    </head>

    <body>

    <?php echo $this->view->getContent(); ?>

        {{ content() }}

    </body>

</html>

I know this way I am getting double the content. But this is for debugging. The output I get is:

I am using chrome browser for testing, and ubuntu server 12.04 for phalcon 1.3.0



7.9k

You must use exit(); after echo to see the message



58.4k

HI You can use $this->view->disable()

you cannot echo from controller due to output buffering. will see output if put ob_flush() after line. if you are using incubator and have debug service set, you can do "$this->debug->dump($var)" if you want to debug quickly



10.1k
Accepted
answer
edited Apr '14

When I used: $this->view->disable(); the output is getting on my screen including the main volt layout 'layer'

But when I remove the line: $this->view->disable();

Nothing on echoing is getting outputted.

This is because:

Phalcon uses its first layout 'layer' as viewdir/index.phtml/volt

Second it searches for the layout that matches the controller (and action) its name.

On the first layour 'layer' with volt language you can use : {{ content() }}

to output the second layout 'layer'. That is what it did. But because I didn't use {{ content()}}

on he controllers layout 'layer' nothing that is outputed through the controller code is getting on the screen

But when using {{content()}} on the second 'layer', you probably will get the output. It works for me.

I hope this will help others too.

Additional info: <?php echo $this->getContent() ?> is the same as volt's {{ content() }}