CakePHP 3.0 HasAndBelongsToMany Input Broken on Edit
Upgrading CakePHP 3.0->3.1 will save mondo head scratching about check-boxs/multi-selects not working right for HasAndBelongsToMany.
3.0 will save the relations in the join table, but will not show them as selected on further edits.
All you should need in your view for it to work is:
(Example is Cart HasAndBelongsToMany Items), editing Cart.
$this->Form->input('Item', array('multiple' => 'checkbox'));
or
$this->Form->input('Item', array('multiple' => true));
And in your controller action
$this->set('items', $this->Cart->Item->find('list'));Written by Kevin Alford
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Did you know?
PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#