cakePHP -- pobranie $id konkretnego rekordu

0

Witam serdecznie,

chciałabym uprzejmie się zapytać, jak pobrać $id (uzwajając framerowka cakePHP), w momencie wybierania konkretnego ucznia , a następnie wyświetlenie jego oceny
Przy założeniu takich tabel:

students

id surname name
1 nazwisko1 imie1
2 nazwisko2 imie2
3 nazwisko3 imie3

assessments

id student_id assessment
1 2 2
2 1 3
3 1 5

Wybór ucznia :

  • view
    -layouts
    • default.ctp
/* ... */
<?php
echo $this->Html->link($student['Student']['name'], array('controller' => 'assessments', 'action' => 'index', 'student' => $student['Student']['id']));
?>

/* ... */

Nie poprawna obsługa wyświetlenia ocen , przedstawia sie następująco:

  • controllers
    • components
      • assessments_controller.php
class AssessmentsController extends AppController {

var $name = ' Assessments';

  function index() { 
		
     $id = $this->params['named']['student'];

     $assessments  = $this-> Assessment ->find('all', array('conditions' => array('Assessment.student_id' => 2 )));
	
     if (isset ($this->params['requested']))   {
	return $assessments;
     }	
  }    
}
?>

po wybraniu ucznia przechodzi do wyświetlenia , gdzie pojawia sie błąd:

Undefined index:  student [APP/controllers/ads_controller.php, line 9]

implementacja wyświetlenia:

  • view
    • ads
      • index.ctp
<table>

        <?php
	$assessments= $this->requestAction(array('controller' => 'assessments', 'action' => 'index'));
            foreach($assessments  as $Assessment): ?>
            <tr>
                <td> <?php echo $Assessment['Assessment']['surname']; ?></td>
            </tr>
        
        <?php
            endforeach;
        ?>
</table>

model w którym uwzględniam relacje miedzy tabelami;

  • models
    • assessment.php
 <?php class Assessment  extends AppModel {

    var $belongsTo = array(
        'Student ' => array(
        'className' => ' Student',
        'foreignKey' => 'student _id',
        'conditions' => '',
        'fields' => '',
        'order' => ''
    ));
    
 }
?>

Próbowałam na wiele sposobów, pobrać $id ucznia, ale bez większych rezultatów:

Cały czas pyta się o zdefiniowanie ['student']; Nie wiem za bardzo jak to zrobić, uprzejmie proszę o wskazówkę ....??

0

nikt nie wie ...?

dodatkowego parametru zabrakło:

 $id = $this->params['named']['student'];
 
 $assessments  = $this-> Assessment ->find('all', array('conditions' => array('Assessment.student_id' =>  $id ) , 'student'=> 'Assessment.student_id' ));
 $this->set(compact('assessments'));
0
 
/* ... */
<?php
echo $this->Html->link($student['Student']['name'], array('controller' => 'assessments', 'action' => 'index', 'student' => $student['Student']['id']));
?>
 
/* ... */

Jakie Ci sie linki generuja? Podaj przykladowy adres url.

1 użytkowników online, w tym zalogowanych: 0, gości: 1