我一直在試圖解決這個問題幾天。請儘可能協助或建議其他方法。我能夠顯示每個學生在鉻,safari和firefox的10節課的總分。但是,我在IE9/10中出現了「此頁無法顯示」的錯誤。cakephp邏輯 - 其他方法獲得相同的結果
我厭倦了調試,發現IE9/10顯示上述錯誤,當我使用for循環通過requestAction。話雖如此,我會要求requestAction得到總分。
爲了得到總分我依賴於每個循環(foreach($ customers as $ customer){...})來獲取每個$ customer ['Customer'] ['id']並將其傳遞給requestAction並返回得分結果。
QNS 1.是否有另一種方法來實現這個結果?
QNS 2.我可以在控制器中做所有事情嗎?如果是這樣,怎麼樣?
控制器
function eachlesson($lessonid, $sessionkey, $customer_id) {
return $this->Score->find('first', array('conditions' => array('Score.test_bk_session_id' => $sessionkey, 'Customer.customers_types' => 'student', 'Score.lesson' => $lessonid, 'Score.customer_id' => $customer_id)));
}
VIEW
<table>
<?php foreach ($customers as $customer) { ?>
<tr>
<td>
<?php echo $customer['Customer']['customers_name']; ?>
</td>
<td>
<?php
$customer_id = $customer['Customer']['id'];
$sessionkey = $this->params['pass'][1];
//LOOP THROUGH 10 TIMES TO GET LESSON 1 - 10 SCORES
for ($i=1; $i<=10; $i++) {
$lessonid = $i;
$score = $this->requestAction('/scores/eachlesson/'.$lessonid."/".$sessionkey."/".$customer_id);
//GETTING THE TOTAL SCORE FOR LESSON 1 TO 10
(int)${'totaleachlesson'.$i} = $score['Score']['BI_pts'] + $score['Score']['FD_pts'] + $score['Score']['PO_pts'] + $score['Score']['WW_pts'] + $score['Score']['MG_pts'] + $score['Score']['FO_pts'];
}
//ADDING THE TOTAL SCORE OF THE 10 LESSONS
$figureofcorrecttotal = $totaleachlesson1 + $totaleachlesson2 + $totaleachlesson3 + $totaleachlesson4 + $totaleachlesson5 + $totaleachlesson6 + $totaleachlesson7 + $totaleachlesson8 + $totaleachlesson9 + $totaleachlesson10;
//DISPLAY THE TOTAL SCORE
echo $figureofcorrecttotal;
?>
</td>
</tr>
<?php } ?>
</table>
HTML輸出
<table class="tablesorter summary3pt2">
<thead>
<tr>
<th width="170" style="padding-right:5px;" class="empty">Name</th>
<th width="120" class="header">No of Correct</th>
</tr>
</thead>
<tbody>
<tr>
<td class="bold" align="right">
Drew Parsons </td>
<td>
2 </td>
</tr>
<tr>
<td class="bold" align="right">
Natasha Francis </td>
<td>
0 </td>
</tr>
<tr>
<td class="bold" align="right">
Johanna Harmon </td>
<td>
0 </td>
</tr>
<tr>
<td class="bold" align="right">
Aubrey Mckenzie </td>
<td>
0 </td>
</tr>
<tr>
<td class="bold" align="right">
Edith Sims </td>
<td>
0 </td>
</tr>
<tr>
<td class="bold" align="right">
Brandy Ruiz </td>
<td>
0 </td>
</tr>
<tr>
<td class="bold" align="right">
Toni Marshall </td>
<td>
0 </td>
</tr>
<tr>
<td class="bold" align="right">
Cedric Nash </td>
<td>
0 </td>
</tr>
<tr>
<td class="bold" align="right">
Penny Maldonado </td>
<td>
0 </td>
</tr>
<tr>
<td class="bold" align="right">
Brandi Perry </td>
<td>
0 </td>
</tr>
<tr>
<td class="bold" align="right">
Conrad Hogan </td>
<td>
0 </td>
</tr>
<tr>
<td class="bold" align="right">
Travis Sparks </td>
<td>
0 </td>
</tr>
<tr>
<td class="bold" align="right">
Winifred Watson </td>
<td>
0 </td>
</tr>
<tr>
<td class="bold" align="right">
Shannon Strickland </td>
<td>
0 </td>
</tr>
</tbody>
</table>
我懷疑那裏和Html的錯誤,但我不能確定,除非你添加一些例子生成的HTML。但是,檢索分數應該直接從控制器內的模型中直接檢索。 RequestAction通常對性能不利,並導致大量開銷。 – thaJeztah 2013-03-22 07:44:46
是的,服務器並不關心你運行的是什麼瀏覽器,所以錯誤將會與生成的HTML一起。發佈。 – 2013-03-22 10:14:16
嗨,大家好。我已經發布了html輸出。我懷疑在HTML中有錯誤。 thaJeztah。你建議我應該從控制器內的模型中檢索結果?你有任何我可以遵循的例子,因爲我需要requestAction來獲得分數結果。 – DANLEE 2013-03-24 04:24:38