2016-10-12 4 views
0

아무 것도 작동하지 않는 것처럼 일치하는 절 (주체 테이블 ID 및 이름)의 데이터를 어떻게 표시합니까? 데이터를 얻을 수 있지만 제목 ID 또는 이름을 표시 할 수 없습니다? 몇 가지 변종을 시도해 본 결과 cakephp3 문서를 확인했는데이 점에 대해서는 아무 것도 말하지 않는 것으로 보입니다. cakephp3에서 일치 절의 데이터를 표시합니다.

오류

가 아닌 객체

//controller 
$tutorSubjects = $this->Tutors->getAllTutorSubjects($searchSubject); 

      foreach($tutorSubjects as $item2): 
     //  
      // debug($item2); 
      debug($item2->Tutor->Subjects->name); 
      debug($item2->Tutors->Subjects->name); 
      debug($item2->Tutors->Subject->name); 
      debug($item2->tutor->subjects->name); 
      debug($item2->subjects->name); 
      debug($item2->Subjects->name); 
      debug($item2->subject->name); 

      endforeach; 

//data 
object(App\Model\Entity\Tutor) { 

    'id' => (int) 12, 
    'last_name' => 'Towe', 
    'first_name' => 'Andre', 
    '_matchingData' => [ 
     'Subjects' => object(App\Model\Entity\Subject) { 

      'id' => (int) 28, 
      'name' => 'Physics: Year 11', 
      '[new]' => false, 
      '[accessible]' => [ 
       '*' => true 
      ], 
      '[dirty]' => [], 
      '[original]' => [], 
      '[virtual]' => [], 
      '[errors]' => [], 
      '[invalid]' => [], 
      '[repository]' => 'Subjects' 

     } 
    ], 

//model 
$query3 = $this->find() 
      // ->contain(['Subjects']) 
       ->select(['Tutors.id','Tutors.last_name','Tutors.first_name']) 
       ->where(['Tutors.tutor_inactive'=>0 
        ]) 
       ->order(['Tutors.first_name' => 'ASC']) 
       ->hydrate(true); 

     if ($subId>0){ 

      $query3->matching('Subjects', function ($q) use ($subId) { 

       return $q 
        ->select(['Subjects.id','Subjects.name']) 
        ->where(['Subjects.id' =>$subId]); 
       }); 

     return $query3; 
     } 

답변

1

당신은 꽤 명확하게 포함하는 _matchingData 특성이 있다고 표시 한 데이터의 속성을 얻으려고 노력하고 그것은 배열 있다고. 따라서 $item2->_matchingData['Subjects']->name이 액세스 할 수 있습니다.

관련 문제