Я работаю над кодом для теста викторины, здесь
function run($id){
//Is this the first question ?
if($this->data){
$question_no = $this->Session->read('Test.qno'); //0
$last_answer = $this->Session->read('Test.last_answer');
$question_no = $question_no + 1; //1
$this->Session->write('Test.qno',$question_no); //Test.qno = 1
$this->Session->setFlash('last_answer'.$this->data['Test']['answer']);
$this->redirect($this->referer());
if($this->data['Test']['answer']==$last_answer){
$score = $this->Session->read('Test.score');
$score = $score + 1 ;
$this->Session->write('Test.score',$score);
$this->Session->setFlash('Correct answer');
}
}
$question_no = $this->Session->read('Test.qno'); //question_no =
if(!$question_no){
$question_no = 0;
$this->Session->write('Test.qno',$question_no);
$this->Session->write('Test.score',0);
}
$question = $this->Test->Question->find('first',array('conditions'=>array('Question.test_id ='=>$id),'offset'=>$question_no));
$answer = $question['Question']['answer'];
$this->Session->write('Test.last_answer',$answer);
if(empty($question)){
$score = $this->Session->read('Test.score');
$this->Session->setFlash('Your Score is '.$score);
$this->Session->write('Test.qno',0);
$this->redirect(array('controller'=>'States','action'=>'index'));
}
else{
$this->set(compact('question'));
}
}
здесь сравнение данных не удается, даже если они оба содержат одно и то же значение, может кто-нибудь сказать мне, почему, здесь $ last_answer извлекается из сессии и содержит число.
$ this-> data ['Test'] ['answer'] берется из формы с переключателем