2016-11-25 9 views
1

(client/results)ビューのロード時に2番目の関数(関数を挿入)を実行したいとします。プライベート関数のイベントを照会します。codeigniter

トリガーのgetResultsがcreate functionも実行したいとき。私は

private function getResults() 
    { 
     $data['emailcount'] = $score = $this->actions->getEmailCount(); 
     $data['sentEmailCount'] = $score = $this->actions->getSentEmailCount(); 
     $data['score'] = $score = $this->actions->getScore(); 
     $data['percentile'] = $percentile = $this->actions->getPercentile($score); 
     $data['timespent'] = $this->input->get('time'); 
//   echo $this->input->get('time'); 
     $this->create(); 
     return $this->load->view('client/results', $data); 
    } 

を試してみましたが、これはエラーを作成するもの

private function getResults() 
    { 
     $data['emailcount'] = $score = $this->actions->getEmailCount(); 
     $data['sentEmailCount'] = $score = $this->actions->getSentEmailCount(); 
     $data['score'] = $score = $this->actions->getScore(); 
     $data['percentile'] = $percentile = $this->actions->getPercentile($score); 
     $data['timespent'] = $this->input->get('time'); 
//   echo $this->input->get('time'); 
     return $this->load->view('client/results', $data); 
    } 

    function create() 
    { 
     $adddata = array(
      'uniID' => '5', 
      'testName' => 'Abintegro E-Tray test', 
      'testID' => '99999', 
      'total' => '20', 
      'userID' => '00000', 
      'useInPercentile' => '1', 
      'correct' => $score = $this->actions->getScore(), 
      'percent' => $score = $this->actions->getScore(), 
      'percentile' => $percentile = $this->actions->getPercentile($score), 
      'dateTaken' => date('Y-m-d H:i:s'), 
//   'timeSpent' => $this->input->get('time') 

     ); 
     $this->actions->add_record($adddata); 
     $this->index(); 
    } 

Fatal error: Maximum function nesting level of '256' reached, aborting! in C:\wamp64\www\New\system\database\DB_query_builder.php on line 2507

とあなたがお互いを呼び出す2つの機能の無限ループを持っ

private function getResults() 
    { 
     { 
      $data['emailcount'] = $score = $this->actions->getEmailCount(); 
      $data['sentEmailCount'] = $score = $this->actions->getSentEmailCount(); 
      $data['score'] = $score = $this->actions->getScore(); 
      $data['percentile'] = $percentile = $this->actions->getPercentile($score); 
      $data['timespent'] = $this->input->get('time'); 
//   echo $this->input->get('time'); 
      $this->create(); 
      return $this->load->view('client/results', $data); 
     }; 
     $this->actions->add_record($adddata); 
     $this->index(); 
    } 

答えて

0
private function getResults() 
    { 
     { 
      $data['emailcount'] = $score = $this->actions->getEmailCount(); 
      $data['sentEmailCount'] = $score = $this->actions->getSentEmailCount(); 
      $data['score'] = $score = $this->actions->getScore(); 
      $data['percentile'] = $percentile = $this->actions->getPercentile($score); 
      $data['timespent'] = $this->input->get('time'); 
//   echo $this->input->get('time'); 

     }; 

     $adddata = array(
      'uniID' => '5', 
      'testName' => 'Abintegro E-Tray test', 
      'testID' => '99999', 
      'total' => '20', 
      'userID' => '00000', 
      'useInPercentile' => '1', 
      'correct' => $score = $this->actions->getScore(), 
      'percent' => $score = $this->actions->getScore(), 
      'percentile' => $percentile = $this->actions->getPercentile($score), 
      'dateTaken' => date('Y-m-d H:i:s'), 
//   'timeSpent' => $this->input->get('time') 

     ); 

     $this->actions->add_record($adddata); 
//  $this->index(); 
     return $this->load->view('client/results', $data); 
    } 
1

てみました無期限にly)。で

あなたgetResults()create()呼び出しのいずれかがgetResults()で終わるのであれば、あなたは再帰ループを作成している場合は、$this->create(); チェックを呼び出します。

+0

ありがとう、私はそれを修正した –

関連する問題