Skip to content

Deprecated since 7.2

This page documents the classic module layer (CBController and cbInit()). It still works in every 7.x release, but new code should use resources and pages.

Use instead: Select::make('tags')->relationship('tags', 'name')->multiple() or CheckboxList.

How To Implement A Many To Many Relationship To Form (E.g : Film -> R <- Actors) ​

Films Table - films ​

Field NameData Type
idint(PK)
created_attimestamp
namevarchar(255)
descriptiontext

Actors Table - actors ​

Field NameData Type
idint(PK)
namevarchar(255)

Films Actors Table - films_actors ​

Field NameData Type
idint(PK)
films_idint(11)
actors_idint(11)

We need multiple select box, so we use select2 with datatable and relationship_table attribute

Code For Form of Films Controller ​

php
$this->form[] - ['label'=>'Name','type'=>'text','name'=>'name'];
$this->form[] = ['label'=>'Description','type'=>'textarea','name'=>'description'];
$this->form[] = ['label'=>'Actors','type'=>'select2','datatable'=>'actors,name','relationship_table'=>'films_actors'];

What's Next ​

Table Of Contents ​

Released under the MIT License.