Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I write data to a HABTM association of a HABTM join table in CakePHP?
    text
    copied!<p>I'm trying to save data with following structure: <img src="https://i.stack.imgur.com/EyLMV.png" alt="alt text"> </p> <p>As you can see, there is HABTM association between <em>users</em> and <em>experiences</em> table. And another HABTM between <em>experiences_users</em> and <em>tags</em>. I created following form:</p> <pre><code>&lt;?php echo $form-&gt;create('Experience', array('action' =&gt; 'addClassic'));?&gt; &lt;?php echo $form-&gt;input('Experience.date', array('dateFormat' =&gt; 'DMY')); echo $form-&gt;input('Experience.time', array('timeFormat' =&gt; '24', 'empty' =&gt; array(-1 =&gt; '---'), 'default' =&gt; '-1')); echo $form-&gt;input('Experience.name'); echo $form-&gt;input('ExperiencesUser.1.note'); echo $form-&gt;input('ExperiencesUser.1.rating'); //echo $form-&gt;input('Tags.Tags', array('multiple' =&gt; 'multiple', 'options' =&gt; $tags)); //echo $form-&gt;input('ExperiencesUser.1.Tags', array('multiple' =&gt; 'multiple', 'options' =&gt; $tags)); //echo $form-&gt;input('ExperiencesUser.1.Tags.Tags', array('multiple' =&gt; 'multiple', 'options' =&gt; $tags)); echo $form-&gt;input('ExperiencesUser.1.confirmed', array('type' =&gt; 'hidden', 'value' =&gt; '1')); echo $form-&gt;input('ExperiencesUser.1.user_id', array('type' =&gt; 'hidden')); echo $form-&gt;input('ExperiencesUser.2.user_id', array('type' =&gt; 'hidden')); ?&gt; &lt;?php echo $form-&gt;end(__('Add', true));?&gt; </code></pre> <p>And everything works well. <em>saveAll</em> method creates new Experience, assings this new experience to two users (via <em>experiences_users</em>) and sets the stuff around.</p> <p>What bothers me is that I want to assign some <em>Tags</em> to newly created <em>experiences_users</em> record (to the first one). I thought, that should be done via some of the commented stuff. Every line of this commented code creates form and sends data to <em>$this->data</em>, but it never gets saved.</p> <p>So my question is: What is the right syntax of <em>$this->data</em> or <em>$form->input</em> in my example to save data into <em>experiences_users_tags</em>? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload