1

私は何日もこの問題を解決しようとしてきました。可能であれば、別の方法を支援または提案してください。chrome、safari、firefox ですべての生徒の 10 レッスンの合計スコアを表示できます。しかし、IE9/10で「このページは表示できません」というエラーが出ました。

デバッグに疲れて、requestAction で for ループを使用すると、IE9/10 で上記のエラーが表示されることがわかりました。そうは言っても、合計スコアを取得するには requestAction が必要です。

合計スコアを取得するには、for each ループ ( 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)));

}

見る

<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>
4

1 に答える 1

1

まず、なぜrequestActionを使用する必要があるのですか? あなたはケーキの慣習に従っていません..少し時間をかけてドキュメントを読む必要があります... Imo、「Score」モデルを「Customer」モデルに関連付け、2つを1回の呼び出しに含めたいと考えています。

<?php
// Customer model.

class Customer extends AppModel {
    var $name = 'Customer';

    var $hasMany = array(
        'Score' => array(
            'className' => 'Score',
            'foreignKey' => 'customer_id',
            'limit' => 10,
            'conditions' => array(
                '<conditions go here>'
            )
        )
    );
}

?>

<?php
// Score model.

class Score extends AppModel {
    var $name = 'Score';

    var $belongsTo = array(
        'Customer' => array(
            'className' => 'Customer',
            'foreignKey' => 'customer_id' // This assumes you have a customer_id field in the 'scores' table.
        )
    );
}

?>

これでモデルが関連付けられました。包含可能な動作をそれらにアタッチしていない場合は、各モデルまたはメインの app_controller.php で以下を追加して実行できます。

var $actsAs = array('Containable');

これで、Customer モデルで検索を実行するときにスコア モデルを含めるだけで、10 個のスコアが自動的に取得されます。

<?php
// customers_controller.php

class CustomersController extends AppController {
    var $name = 'Customers';

    function index() {
        // Contain the child method.
        $this->Customer->contain(array(
            'Score' => array(
                'conditions' => array(
                    'Score.test_bk_session_id' => $sessionkey,
                    'Score.lesson' => $lessonid
                )
            )
        ));
        $customers = $this->Customer->find('all', array(
            'conditions' => array(
                'Customer.customers_types' => 'student'
            )
        ));
        // Now you have all your customers, AND their associated
        // scores. No more request action needed (never use that imo)
        $this->set('customers', $customers);

        // Your array should look like this:
        // $customers =
        //array(
        //    [0] => array(
        //        'Customer' => array(<CustomerArray>),
        //        'Score' => array(<ScoreArray>)
        //    ),
        //    [1] => ...
        //)
    }
}

?>

私はこれをかなり速く書いたので、間違いや間違った仮定を許してください. これがあなたの問題に役立つことを願っています。

于 2013-03-25T21:43:36.127 に答える