-1

から取得している とcourse_id一致させたい。$courseInfo$cLID

この$clID['Relationscl']['course_id']行を変更するとすべて問題ありませんが、別の方法ではUndefined index: Relationscl1のようなエラーが表示されます。

これが私のコードです:

$this->loadModel('Course');
$this->loadModel('Lecturer');


$clID = $this->Relationscl->find('all', array(
        'conditions' => array(
                'student_id' => $id

        ),
        'fields' => array(
                'course_id','lecturer_id'
        )
));



$this->set('clIDs', $clID);

$courseInfo = $this->Course->find('first',array(
        'conditions' => array(
                'course_id' => $clID['Relationscl']['course_id']
        ),
        'fields' => array(
                'course_name','course_code','course_credit'
        )
));


$this->set('cInfos', $courseInfo);
4

1 に答える 1

0

私が間違っている場合は修正してください。ただし、find('all') 関数はインデックス付きの配列を返すため、次のようになります。

$clID = array( 0 => array('Relationscl'=>array('course_id'=>1 /*and more fields*/)),
               1 => array('Relationscl'=>array('course_id'=>2 /*and more fields*/))
        /*etc*/);

明らか$clID['Relationscl']に未定義です。で試してください$clID[0]['Relationscl']それも奇妙に思えますが、 1 枚のレコードfind('all')だけを使用する予定がある場合は、なぜそれを行うのでしょうか。または、その定義をループ内に設定しますか?find('first')$courseInfo

于 2013-06-21T13:58:34.583 に答える