[英]Debugging Undefined Offset in CakePhp
I am receiving the following error: 我收到以下错误:
Notice (8): Undefined offset: 47 [APP/Template\\CoursesEnrolled\\view.ctp, line 75]
注意(8):未定义的偏移量:47 [APP / Template \\ CoursesEnrolled \\ view.ctp,第75行]
I have tried debugging the line but I'm stuck with what to do. 我已经尝试调试生产线,但是我该怎么办。
My view.ctp looks like this: 我的view.ctp看起来像这样:
$modulesEnrolled = Cake\Utility\Hash::combine($coursesEnrolled->courses_enrolled_modules,
'{n}.course_module_id','{n}');
// debug($modulesEnrolled);
$allModulesCompleted = true;
if (!empty($coursesEnrolled->course->course_modules)): ?>
<div class="">
<table class="table table-bordered table-hover" id="toggletable">
<thead>
<tr>
<th><?= __('Title') ?></th>
<th><?= __('Type') ?></th>
<th class="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($coursesEnrolled->course->course_modules as $courseModules): ?>
<tr>
<td><?= h($courseModules->title) ?></td>
<td><?= h($courseModules->type) ?></td>
<td class="actions">
<?php
if($allModulesCompleted && $modulesEnrolled[$courseModules->id]['status'] == 'Pending') { //this is line 75
$allModulesCompleted = false;
}
Any help would be greatly appreciated. 任何帮助将不胜感激。
My guess is, one of your arrays doesn't start at 0. 我的猜测是,您的一个数组不是从0开始。
The $courseModules->id
doesn't match the any key in the $modulesEnrolled
array. $courseModules->id
与$modulesEnrolled
数组中的任何键都不匹配。
I would try either incrementing or decrementing by 1, maybe try the following: 我会尝试增加或减少1,或者尝试以下操作:
$IDHere = (int)$courseModules->id - 1;
if($allModulesCompleted && $modulesEnrolled[$IDHere]['status'] == 'Pending') { //this is line 75
$allModulesCompleted = false;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.