Echo/Print in Controller

Hi, Can I actually echo or print a variable in Controller? I noticed that I need to put it first in the View in order to print the variable. This is for testing purposes only such that I know what data/value is the variable contains.

below is the code that is not working class PollController extends \Phalcon\Mvc\Controller {

public function indexAction()
{
    echo "HELLO";
}


81.1k

You need to tell Phalcon\Mvc\View where to place the output generated in the controller on the current view: ```php <?php echo $this->view->getContent(); ?> ``` Volt: ```php {{ content() }} ```



6.1k

@Phalcon what i mean is I don't want to use the Volt or the View for the printing... i want it to be printed directly in Controller is this possible?

die(var_dump($var));
class PollController extends \Phalcon\Mvc\Controller
{

    public function indexAction()
    {
        $this->view->disable();
        echo "HELLO";
    }
}


6.1k

thank you guys :D

edited Jun '16

define yourself a helper function and conditionally disable output buffering:

/**
 * Functional replacement for "echo $var" without the need to disable something or to die.
 */
function echof($var) {
   echo $var;
   ob_get_level() && ob_flush();    // flush output buffer if active
}