【问题标题】:Yii2 error:Maximum function nesting level of '100' reached, abortingYii2 错误:达到“100”的最大函数嵌套级别,正在中止
【发布时间】:2014-11-21 10:00:43
【问题描述】:

在 _form.php 中,我尝试使用这个简单的代码,但出现错误:

<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use app\models\State;



/* @var $this yii\web\View */
/* @var $model app\models\State */
/* @var $form yii\widgets\ActiveForm */

 $model = new State();
?>



<?= $this->render('_form', [
        'model' => $model,
        ]) ?>

为什么我会收到此错误。因为相同的代码运行良好。

【问题讨论】:

标签: php yii2


【解决方案1】:

如果这确实是来自“_form.php”的代码,那么下面的代码会在自身内部递归地渲染 _form.php:

<?= $this->render('_form', [
        'model' => $model,
        ]) ?>

【讨论】:

    【解决方案2】:

    Joshi 是正确的,它发生的原因是因为您调用的是 render() 而不是 renderPartial()。将您的代码更改为此,错误将消失,您的部分将按预期显示:

    <?= $this->renderPartial('_form', [
            'model' => $model,
        ]) ?>
    

    【讨论】:

      猜你喜欢
      • 2012-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-30
      • 2013-07-03
      • 1970-01-01
      • 1970-01-01
      • 2013-07-23
      相关资源
      最近更新 更多