2017-10-19 2 views
0

아래 예제에서 ID 대신 값을 표시하려면 어떻게해야합니까?CakePHP 3 관련 데이터를 형태로 표시

표 문서가 포함되어

이 .ctp에서
$test = $this->Documents->find('all',['conditions' => ['review_date'=>date('Y-m-d', strtotime('2022-01-01')) ] ]); 

그것을 보여줍니다 (이 중요한 경우)하지 DocumentsController에 ID가, 제목, 몸, person_id로, 나는하지만, 이런 식으로 얻을
을 review_date 같은 :

<tbody> 
     <?php foreach ($test as $document): ?> 
     <tr> 
      <td><?= $document->id; ?></td> 
      <td><?= $document->person_id; ?></td> 
     </tr> 
     <?php endforeach; ?> 
</tbody> 

그리고 나는을 person_id로 대신 의 사람의 이름을 표시합니다. ...

public function add() 
    { 
     $this->loadModel('Documents'); 
     $this->loadModel('Persons'); 
     $this->loadModel('SelfReports'); 
     $this->loadModel('PlannedQuestions'); 
     $agenda = $this->Agendas->newEntity(); 
     if ($this->request->is('post')) { 
      $agenda = $this->Agendas->patchEntity($agenda, $this->request->getData()); 
      if ($this->Agendas->save($agenda)) { 
       $this->Flash->success(__('The agenda has been saved.')); 

       return $this->redirect(['action' => 'index']); 
      } 
      $this->Flash->error(__('The agenda could not be saved. Please, try again.')); 
     } 
     $per = $this->Persons->find('all'); 
     $tes = $this->Documents->find('all',[ 
      'conditions' => ['review_date'=>date('Y-m-d', strtotime('2022-01-01'))], 
     'fields' => ['Documents.id','RefArticles.article_number','Persons.name']]); 
     $selfreports = $this->SelfReports->find('all',['conditions' => ['next_visit_date'=> date('Y-m-d', strtotime('thursday this week'))]]); 
     $plannedquestions = $this->PlannedQuestions->find('list'); 
     $this->set(compact('agenda', 'tes')); 
     $this->set('_serialize', ['agenda']); 
    } 

답변

0

내가 나 자신을 내가 이것을 사용
을하고 작업의 : 모든 컨트롤러에서 함수를 추가 컨트롤러

$tes = $this->Documents->find('all',[ 
      'contain'=>['Persons'], 
      'conditions' => ['review_date'=>date('Y-m-d', strtotime('2022-01-01'))]]); 

과의 .ctp

<td><?= $document->person->surnamepat; ?></td> 
관련 문제