php - yiiadmin - many-to-many in yii-framework admin interface -
i extending yii-s admin extension, yiiadmin.
what easiest way listbox multiple-select field in model-create view, display many-to-many relation, example have 'pivot' table holds these article-category relationships, along article , category tables.
i have these relations defined in models, , managed other relations list view, author.name acquired through author_id field in article table.
now want article creation form contain multiple select listbox save pivot table automatically multiple choices of categories article belongs to.
those be, therefore, multiple entries/rows article_category pivot table 1 article submission.
at same time, article table not contain field refers category. pivot table therefore picks article's id attribute , connects categorie's (another model/table) id , makes row out of this.
so, example, have these tables/models:
article >>> id | title | author | text
category >>> id | name | description
articlecategory >>> id | article_id | category_id
and want populate third pivot table multiple rows multiple select listbox article create view/form of yiiadmin (often through 1 submission).
i want automatically render category.name category table listbox, appropriately related category id-s can show names category table, , choice & submission populate pivot table id-s of category (therefore not names)
is possible, , way this?
try extension more save many_many relationships:
http://www.yiiframework.com/extension/cadvancedarbehavior/
(the gii-template-collection uses , provides crelated widget create populated relation form elements you, works pretty i've tried it: http://www.yiiframework.com/extension/gii-template-collection/)
this 1 claims similar many-to-many relationships: http://www.yiiframework.com/extension/save-relations-ar-behavior/
also, it's easy write code yourself. populate chtml::listbox models it's related to, in action iterate through them , add relationships 'pivot' table simple sql. or create model pivot table , use regular save() ar methods too. can stuff in aftersave() model event well, instead of controller action.
Comments
Post a Comment