【发布时间】:2026-01-16 14:05:02
【问题描述】:
当我将嵌套级别设置为超过 415 时,它会给出错误页面不工作并将其设置为 400 然后给出错误达到“415”的最大函数嵌套级别,中止!
function actionIndex(){
$limit = 1000;
ini_set('xdebug.max_nesting_level', $limit);
$queryTopics = "SELECT tr.id,tr.`parent_id`, tr.`child_id`, tr.`order_by`, tr.`level`, tr.`child_id` AS `tid`, t.`name`,t.`seo_name`
FROM `topic_relations` tr
LEFT JOIN `topics` t ON tr.`child_id` = t.`id`
WHERE t.`status` = 1";
$topicss = \Yii::$app->db->createCommand($queryTopics)->queryAll();
$topics = array();
foreach ($topicss as $key => $value) {
$parentIdCombination = $this->findAllParent($value['id']);
$combination = array_reverse($parentIdCombination);
$combinations = implode($combination, ' ');
$topics['parent_combination'] = $combinations;
unset($combination);
$topics[] = $value;
}
$data['topicsParentChildArr'] = $this->buildTopicsTree($topics);
echo '<pre>';
print_r($topics);
return $this->render('index',['data'=>$data]);
}
递归调用这个函数
function findAllParent($id) {
global $combination;
$parentTopicQuery = "SELECT * FROM `topic_relations` where id=".$id;
$topic_row = \Yii::$app->db->createCommand($parentTopicQuery)->queryOne();
if($topic_row['level']>0) {
$combination[] = $topic_row['child_id'];
$parentTopicQuery1 = "SELECT * FROM `topic_relations` where child_id=".$topic_row['parent_id'];
$topic_row1 = \Yii::$app->db->createCommand($parentTopicQuery)->queryOne();
$this->findAllParent($topic_row1['id']);
}else {
$combination[] = $topic_row['child_id'];
}
//var_dump($combination);
return $combination;
}
【问题讨论】:
-
您的问题是什么?如果这是一个生产站点,为什么要在其中运行 xdebug?
-
如何提高最大嵌套循环级别??
-
你需要在 php.ini 上更改它,它被称为
xdebug.max_nesting_level*.com/questions/4293775/… -
我做了,但它不适合我。
-
我认为这是一个拼写错误的情况:最里面的查询实际上是在执行外部查询,而不是内部查询。内部应该是
createCommand($parentTopicQuery1)而不是createCommand($parentTopicQuery)(注意“1”)。因此,代码将永远递归,直到发生错误。我投票关闭为错字。
标签: php loops yii2 yii2-advanced-app