/** * @inheritdoc */ public function format($record, $view) { HighlightAsset::register($view); $view->registerJs('hljs.highlightBlock(document.getElementById("response-content"));'); $view->registerCss('pre code.hljs {background: transparent}'); return Html::tag('pre', Html::tag('code', Html::encode($record->content), ['id' => 'response-content', 'class' => 'html'])); }
/** * @inheritdoc */ public function format($record, $view) { try { $data = Json::decode($record->content); } catch (InvalidParamException $e) { return parent::format($record, $view); } $content = Json::encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); HighlightAsset::register($view); $view->registerJs('hljs.highlightBlock(document.getElementById("response-content"));'); $view->registerCss('pre code.hljs {background: transparent}'); return Html::tag('pre', Html::tag('code', Html::encode($content), ['id' => 'response-content', 'class' => 'json'])); }
/** * @inheritdoc */ public function format($record, $view) { $dom = new \DOMDocument(); $dom->formatOutput = true; try { $dom->loadXML($record->content); } catch (ErrorException $e) { return parent::format($record, $view); } $content = $dom->saveXML(); HighlightAsset::register($view); $view->registerJs('hljs.highlightBlock(document.getElementById("response-content"));'); $view->registerCss('pre code.hljs {background: transparent}'); return Html::tag('pre', Html::tag('code', Html::encode($content), ['id' => 'response-content', 'class' => 'xml'])); }
<div class="tab-content"> <div id="response-body" class="tab-pane"> <?php $contentType = !empty($record->headers['Content-Type']) ? $record->headers['Content-Type'][0] : ''; $formatterConfig = 'zhuravljov\\yii\\rest\\formatters\\RawFormatter'; foreach ($this->context->module->formatters as $mimeType => $config) { if (strpos($contentType, $mimeType) === 0) { $formatterConfig = $config; break; } } /** @var \zhuravljov\yii\rest\formatters\RawFormatter $formatter */ $formatter = \Yii::createObject($formatterConfig); echo $formatter->format($record); \zhuravljov\yii\rest\HighlightAsset::register($this); $this->registerJs('hljs.highlightBlock(document.getElementById("response-content"));'); $this->registerCss('pre code.hljs {background: transparent}'); ?> </div><!-- #response-body --> <div id="response-headers" class="tab-pane"> <table class="table"> <thead> <tr> <th>Name</th> <th>Value</th> </tr> </thead> <tbody> <?php