Yii2呈现视图将HTML代码显示为文本

Yii2呈现视图将HTML代码显示为文本,yii2,yii2-advanced-app,Yii2,Yii2 Advanced App,我在Yii2中渲染视图时遇到了一个问题,这已经困扰了我好几天了。渲染工作正常,直到一天早上它决定不工作。该视图显示原始HTML代码,而不是用户界面 下面是渲染视图的控制器的代码 if ($fails == TRUE) { Yii::$app->session->setFlash('error', 'The following records failed validation, kindly update and submit'); return $this->

我在Yii2中渲染视图时遇到了一个问题,这已经困扰了我好几天了。渲染工作正常,直到一天早上它决定不工作。该视图显示原始HTML代码,而不是用户界面

下面是渲染视图的控制器的代码

if ($fails == TRUE)
{
    Yii::$app->session->setFlash('error', 'The following records failed validation, kindly update and submit');
    return $this->render('failedvalidation',['fails' => $fails,]);
} else {
    Yii::$app->session->setFlash('success', 'File uploaded successfully,waiting approval');
    return $this->redirect(Yii::$app->request->referrer);
}
下面是我的视图文件(failedvalidation.php)的代码


参考号
全名
身份证号码
信用账户
数量
叙述
行动

嗨,我也遇到过类似的情况,挣扎了几天。最后我发现在我的一个函数中有这样的语句
\Yii::$app->response->format=\Yii\web\response::format\u JSON
所以我禁用了这个声明。它奏效了,但我需要找到更好的解决方案。希望这有帮助

<?php
use yii\helpers\Html;
use yii\bootstrap\Modal;
use yii\helpers\Url;
?>
<div class="bulkpayments-view">
<div class="box box-default">
    <div class="table-responsive">
        <table class="display nowrap" id="example1">
            <thead>
            <tr>
                <th>Ref No</th>
                <th>Full Names</th>
                <th>Id No</th>
                <th>Credit Account</th>
                <th>Amount</th>
                <th>Narration</th>
                <th>Action</th>
            </tr>
            </thead>
            <tbody>
            <?php foreach($fails as $data) {?>
                <tr class="gradeX">
                    <td><?= $data['BENEFICIARYREFNO'];?></td>
                    <td><?= $data['BENEFICIARYFULLNAMES'];?></td>
                    <td><?= $data['IDNO'];?></td>
                    <td><?= $data['TOACCOUNT'];?></td>
                    <td><?= $data['AMOUNT'];?></td>
                    <td><?= $data['NARRATION'];?></td>
                    <td><?= Html::button('<i class="fa fa-pencil"></i> 
    Update', ['value' => Url::to(['update-failed-validation', 'id' => 
    $data['ID'],'transid' => $data['TRANSACTIONID']]), 'class' => 'button btn 
     btn-primary btn-xs']) ?></td>

                </tr>
            <?php }?>
            </tbody>
        </table>
    </div>
</div>
</div>
<?php
Modal::begin([
'header' => '<h4>Update Record</h4>',
'id' => 'modal',
'size' => 'modal-lg',
'clientOptions' => ['backdrop' => 'static', 'keyboard' => false],
]);
  echo '<div id="content"></div>';
 Modal::end();
 ?>

<?php
$js = <<<JS
$('.button').click(function() {
if($('#modal').data('shown.bs.modal')) {
    $('#modal').find('#content')
        .html('<i class="fa fa-spinner fa-pulse fa-2x"></i>')
        .load($(this).attr('value'));
} 
else {
    $('#modal').modal('show')
        .find('#content')
        .html('<i class="fa fa-spinner fa-pulse fa-2x"></i>')
        .load($(this).attr('value'));
}
});
JS;
$this->registerJs($js);
?>
<?php
$script = <<< JS
$(function () { 
    $('#example1').DataTable( {
      dom: 'Bfrtip',
        buttons: [
        {
            //extend: 'excel',
            exportOptions: {
                orthogonal: 'sort'
            }
        }        
        ],
        columnDefs: [{
           targets:[0,1,2],
           render: function(data, type, row, meta){
              if(type === 'sort'){
                 //data = ' ' + data ;
                  return "\u200C" + data ; 
              }

              return data ;   

           }
        }]

} );
});
JS;
$this->registerJs($script);
?>
<style>
.box{
    padding:30px;
}
</style>