Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the var_dump output directly from the controller?

Tags:

phalcon

class IndexController extends \Phalcon\Mvc\Controller
{
    public function indexAction()
    {
        $custom = "Custom variable";
        var_dump($custom);
    }
}

How to display the result not using the variables in the template?

P.S. The result of the Echo function is also suppressed. I understand that this is the wrong approach, but it is a quick way to debug the variables.

like image 607
Yury Avatar asked Jan 26 '13 09:01

Yury


People also ask

What is Var_dump () function explain with example?

The var_dump() function is used to dump information about a variable. This function displays structured information such as type and value of the given variable. Arrays and objects are explored recursively with values indented to show structure. This function is also effective with expressions.

What does Var_dump return?

@JMTyler var_export returns a parsable string—essentially PHP code—while var_dump provides a raw dump of the data. So, for example, if you call var_dump on an integer with the value of 1, it would print int(1) while var_export just prints out 1 .

What is the difference between Var_dump () and Print_r ()?

var_dump() displays values along with data types as output. print_r() displays only value as output. It does not have any return type. It will return a value that is in string format.

Why Var_dump () is preferable over Print_r ()?

It's too simple. The var_dump() function displays structured information about variables/expressions including its type and value. Whereas The print_r() displays information about a variable in a way that's readable by humans. Example: Say we have got the following array and we want to display its contents.


1 Answers

if you don't see output from controller check if in your template file you have this line:

{{ content() }}

you can use php's var_dump in any place of your code:

var_dump($var);exit;

exit; is to stop anything what happens after this line.

You can also dump your vars in volt's template with volt's function:

{{dump(var)}}

dump() is same as var_dump() Here are some more useful volt functions:

http://docs.phalconphp.com/en/latest/reference/volt.html#functions

like image 167
Lukas Liesis Avatar answered Oct 12 '22 05:10

Lukas Liesis