2017-10-19 1 views
0

Wie kann ich im folgenden Beispiel den Wert anstelle der ID anzeigen?CakePHP 3 Anzeige zugehöriger Daten im Formular

Tabelle Dokumente enthalten: id, Titel, Körper, person_id, review_date
ich wie diese zu erhalten, aber nicht in DocumentsController (wenn es wichtig ist):

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

In .ctp es zeigt dies wie:

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

Und ich will stattdessen Namen dieser Person zur Anzeige von person_id. Alle Funktion aus dem Controller hinzufügen:

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']); 
    } 

Antwort

0

Ich mache es mir ...
ich dies und es Arbeit verwenden: Kontroller

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

Und in .ctp

<td><?= $document->person->surnamepat; ?></td>