, nachdem ich das Abfrageergebnis zu erhalten, habe ich Problem die damit verbundenen Zugriff auf Tabellen, die ich in meiner Tabelle Klasse debug ($ query) beigetreten:verschiedene Möglichkeiten zugehörige Tabellen zuzugreifen
src\Model\Table\ComlibsTable.php (line 30)
[
(int) 0 => object(App\Model\Entity\Comlib) {
'id' => (int) 1,
'question' => 'how to kill someone?',
'answer' => (int) 2,
'asked' => (int) 90,
'tags' => 'kill,proffesional killer',
'created' => null,
'modified' => null,
'answers' => [
(int) 0 => object(App\Model\Entity\Answer) {
'id' => (int) 1,
'question_id' => (int) 1,
'answer' => 'the crackpot will attack the will of the darkness and then i starve',
'rate' => (float) 11.2,
'view' => (int) 22,
'helpful' => '11|22',
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Answers'
}
],
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Comlibs'
}
]
jetzt weiß ich, dass ich zugreifen kann Comlib-Entität wie: $ query [0] ['question']; aber ich frage mich, gibt es eine andere Möglichkeit, auf die Entitäten wie $ query-> question zuzugreifen; und wie ich die Antworten Einheit zugreifen kann, mein Controller-Code:
<?php
namespace App\Controller;
use App\Controller\AppController;
class ComlibsController extends AppController {
public function index() {
}
public function getResult(){
$this->viewBuilder()->layout('comlib');
$live_req = $this->request->data['searchBox'];
$query = $this->Comlibs->LFM($live_req);
$this->set('question',$query[0]['question']); // does work
$this->set('answer',$query['answers'][0]['id']); // does not work
}
}
LFM Funktion
public function LFM($live_req) {
$query = $this->find()->where(['question' => $live_req])->contain(['Answers']);
$query = $query->toArray();
debug($query);
//include 5 answer
return $query;
}
}
tnx für jede Hilfe
Zeigen Sie Ihre Modell Assoziationen und Ihre Comlibs-> LFM Funktion – rrd
Was meinst du mit Modell Assoziationen? Wenn du meinst, dass es eine Entität gibt, in der sich nur die Kuchen-PHP-Struktur für eine Entität ohne Funktion befindet, hat das Comlib-Modell eine Initialisierungsfunktion im Modell. das ist es –