0
ディアーズ、CakePHPの3 - index.ctpの複数の関係同じテーブル表示
Iは、ユーザーテーブルのIDフィールドに関連する2つのフィールド(solicitanteとresolvedor)を有し、どのようindex.ctpの両方を表示することができ? 私は2つを入れたときに、情報が
マイindex.ctp
<?= $chamado->has('user') ? $this->Html->link($chamado->user->nome, ['controller' => 'Users', 'action' => 'view', $chamado->user->id]) : '' ?>
繰り返さので、私は以下のコードを使用しますが、私は2つのフィールドを区別する方法がわからない、私は一つのフィールドを置きます私のコントローラ
public function index()
{
$this->paginate = [
'contain' => ['Users']
];
$chamados = $this->paginate($this->Chamados);
$this->set(compact('chamados'));
$this->set('_serialize', ['chamados']);
}
マイモデル
public function initialize(array $config)
{
parent::initialize($config);
$this->setTable('chamados');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('Users', [
'foreignKey' => 'solicitante',
'joinType' => 'INNER'
]);
}
がsを次のcreen画像: