Foreign Keys
To reference data from a different database table (1:n relation), you can use foreign keys. Foreign sets (m:n relation) are described at the bottom of the page.
Parameters:
- ftable: foreign table
- flabel: the attribute to show
- fsave: the attribute to save
- flabel2: another attribute to show
- fconcat: the string to concat label and label2 with
- frestr: restriction on the foreign table
Sample Code
// create form object
$forms = new pnFormTrash("people");
$forms->edit("firstname", "color");
$forms->show("firstname", "color");
$forms->setForeignKey("color",
array(
'ftable'=>"colors",
'flabel'=>"name",
'fsave'=>"id"
)
);
// create html
$forms->doit();
Live Sample
Foreign Sets
Foreign Sets allow a reference with a m:n relation a a different database table.
Parameters
- ftable: foreign table
- flabel: the attribute to show
- fsave: the attribute to save in the m:n-table
- input: type for selection while editing
- mtable: m:n-table
- mforeign: attribute of m:n-table for foreign id
- mthis: attribute of m:n-table for this id
- frestr: restriction on the foreign table
- allnone: add checkboxes to mark all or none values
Sample Code
// create form object
$forms = new pnFormTrash("people");
$forms->edit("firstname", "color");
$forms->show("firstname", "color");
$forms->setForeignSet("tmpfield",
array(
'ftable'=>"colors",
'flabel'=>"name",
'fsave'=>"id",
'input'=>"checkbox",
'mtable'=>"colorpeople",
'mforeign'=>"color",
'mthis'=>"people",
)
);
// create html
$forms->doit();