hasOne cakephp 3

Par agencep, il y a 10 ans


Bonsoir,

Je débute avec la version 3 de cakephp
mais j'ai un petit soucis avec les liaisons :

Mon formulaire qui vient de la partie Ads contient des champs qui doivents être injectés dans la table automobiles

Pour les champs qui doivent être injecté dans la table automobiles sont :

<?php echo $this->Form->input('Automobiles.brand_id', ['empty' => __("Veuillez choisir")]) ?> <?php echo $this->Form->input('Automobiles.bodywork_id', ['empty' => __("Veuillez choisir")]) ?> <?php echo $this->Form->input('Automobiles.fuel_id', ['empty' => __("Veuillez choisir")]) ?> <?php echo $this->Form->input('Automobiles.transmission_id', ['empty' => __("Veuillez choisir")]) ?> <?php echo $this->Form->input('Automobiles.drivegear_id', ['empty' => __("Veuillez choisir")]) ?> <?php echo $this->Form->input('Automobiles.power_id', ['empty' => __("Veuillez choisir")]) ?> <?php echo $this->Form->input('Automobiles.Annee', ['type' => 'date']) ?> <?php echo $this->Form->input('Automobiles.Kilometrage') ?>

le code qui va s'occuper de ça est :

if ($this->request->is('post')) { $ad = $this->Ads->patchEntity($ad, $this->request->data, [ 'associated' => ['Automobiles'] ]); $ad['category_id'] = $category_id; if ($this->Ads->save($ad, [ 'associated' => ['Automobiles'] ])) { $this->Flash->success(__('Votre annonce a été sauvegardé.')); return $this->redirect(['action' => 'index']); } $this->Flash->error(__('Impossible d\'ajouter votre annonce.')); }

et voici le debug de $this->request->data

[ 'id' => '', 'name' => 'test de x', 'description' => 'On sait depuis longtemps que travailler avec du texte lisible et ...', 'section_id' => '1', 'price' => '10000', 'expire_id' => '15', 'Automobiles' => [ 'brand_id' => '3', 'bodywork_id' => '4', 'fuel_id' => '2', 'transmission_id' => '1', 'drivegear_id' => '1', 'power_id' => '9', 'Annee' => [ 'year' => '2015', 'month' => '06', 'day' => '10' ], 'Kilometrage' => '2011' ] ]

la partie concernant la table ads s'injecte bien par contre la partie Automobiles non, ou est l'erreur svp ?

Merci

3 réponses

agencep, il y a 10 ans

Bon a priori j'ai trouver l'erreur ==> c'est le nom du champ concernant automobiles

<?php echo $this->Form->input('Automobiles.brand_id', ['empty' => __("Veuillez choisir")]) ?> =====> <?php echo $this->Form->input('automobile.brand_id', ['empty' => __("Veuillez choisir")]) ?>
agencep, il y a 10 ans

Bon a priori j'ai trouver l'erreur ==> c'est le nom du champ concernant automobiles

<?php echo $this->Form->input('Automobiles.brand_id', ['empty' => __("Veuillez choisir")]) ?> =====> <?php echo $this->Form->input('automobile.brand_id', ['empty' => __("Veuillez choisir")]) ?>
Huggy, il y a 10 ans

Une petite faute aussi là
"Votre annonce a été sauvegardée"