I am working on Magento 2.
if ($this->getRequest()->isAjax()) {
$layout = $this->_layout;
}
How can I print or debug value of $layout
in above code ??
On top of what Ashar Riaz said, you can also use the debug
method from \Psr\Log\LoggerInterface
:
$this->_logger->debug(var_export($layout, true));
IIRC, the values will be logged under var/log/debug.log
you can print $layout in log file like in below code and see results in var/log/debug.log file
class Example{
protected $_logger;
public function __construct(
\Psr\Log\LoggerInterface $logger, //log injection
array $data = []
) {
$this->_logger = $logger;
parent::__construct($data);
}
public function someExampleMethod() {
/*
some logic of method
*/
//accessing to logger instance and calling log method
$this->_logger->log('some text or variable');
/// for array use this
// $this->_logger->log(100,print_r($layout,true));
}
}
you can also print it like that to see result
print_r($layout);exit;
You can print any object using debug function. Review below link
for print layout object you can use
$layout->debug()
Hope, it will be helpful.
print_r($layout);
var_dump()
is a good way too, you could use <pre>
to format the output.
echo "<pre>";
var_dump($layout);
echo "</pre>";
exit;