after using: bin \ cake bake all name_table1 and bin \ cake bake all name_table2, i have a drop-down list with the id of my table1 in the view of table 2. I would like to display the column name 1 instead of id 1 in the drop-down list, but when I save that I memorize the id.
I use cakephp 3.
villeController :
`
<?php
namespace App\Controller;
use App\Controller\AppController;
/**
* Ville Controller
*
* @property \App\Model\Table\VilleTable $Ville
*
* @method \App\Model\Entity\Ville[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = [])
*/
class VilleController extends AppController
{
/**
* Index method
*
* @return \Cake\Http\Response|void
*/
public function index()
{
$ville = $this->paginate($this->Ville);
$this->set(compact('ville'));
}
/**
* View method
*
* @param string|null $id Ville id.
* @return \Cake\Http\Response|void
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function view($id = null)
{
$ville = $this->Ville->get($id, [
'contain' => []
]);
$this->set('ville', $ville);
}
/**
* Add method
*
* @return \Cake\Http\Response|null Redirects on successful add, renders view otherwise.
*/
public function add()
{
$ville = $this->Ville->newEntity();
if ($this->request->is('post')) {
$ville = $this->Ville->patchEntity($ville, $this->request->getData());
if ($this->Ville->save($ville)) {
$this->Flash->success(__('Sauvegardé'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('Echec, veuillez essayer encore !'));
}
$this->set(compact('ville'));
}
/**
* Edit method
*
* @param string|null $id Ville id.
* @return \Cake\Http\Response|null Redirects on successful edit, renders view otherwise.
* @throws \Cake\Network\Exception\NotFoundException When record not found.
*/
public function edit($id = null)
{
$ville = $this->Ville->get($id, [
'contain' => []
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$ville = $this->Ville->patchEntity($ville, $this->request->getData());
if ($this->Ville->save($ville)) {
$this->Flash->success(__('The ville has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('Echec, veuillez essayer encore !'));
}
$this->set(compact('ville'));
}
/**
* Delete method
*
* @param string|null $id Ville id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$ville = $this->Ville->get($id);
if ($this->Ville->delete($ville)) {
$this->Flash->success(__('Sauvegardé'));
} else {
$this->Flash->error(__('Echec, veuillez essayer encore !'));
}
return $this->redirect(['action' => 'index']);
}
/**
* export method
* exporter en fichier excel
*
*/
public function exporteData()
{
$datatable = '';
$datatable = '