Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP saving foreignKeys not working
    primarykey
    data
    text
    <p>I have 3 tables: Computers hasMany Brands, Brands belongsTo Computers and Parts. Now i have these fields in my Brands <code>description</code>,<code>computer_id</code>,<code>part_id</code>. I have the code below to save my data. It will save the description and part_id....But my computer_id does not save at all. <br><br> Usually my URL written <code>http://192.168.6.253/computers/brands/add/1</code> where 1 is computer_id. <br><br> How will I save it? Im still beginner in this framework<br></p> <p>Controller</p> <pre><code>public function add($id = null) { if (!$id) { throw new NotFoundException(__('Invalid post')); } //Assign value to link computer_id $data = $this-&gt;Brand-&gt;Computer-&gt;findById($id); $this-&gt;set('computers', $data); //assign select values to parts select $this-&gt;set('parts', $this-&gt;Brand-&gt;Part-&gt;find('list', array('fields' =&gt; array('description')))); if ($this-&gt;request-&gt;is('post')) { $this-&gt;Brand-&gt;create(); if ($this-&gt;Brand-&gt;save($this-&gt;request-&gt;data)) { $this-&gt;Session-&gt;setFlash(__('Your post has been saved.')); $this-&gt;redirect(array('action' =&gt; 'table/'.$id)); } else { $this-&gt;Session-&gt;setFlash(__('Unable to add your post.')); } } } </code></pre> <p>View</p> <pre><code>&lt;?php echo $this-&gt;Form-&gt;create('Brand'); echo $this-&gt;Form-&gt;input('part_id',array('empty'=&gt;' ')); echo $this-&gt;Form-&gt;input('description'); echo $this-&gt;Form-&gt;input('computer_id',array('type'=&gt;hidden)); echo $this-&gt;Form-&gt;end('Save Post'); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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