Yii Framework Forum: how to create multi model form - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

how to create multi model form

#1 User is offline   Daniel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 292
  • Joined: 26-September 09

Posted 05 November 2017 - 05:09 PM

Dear All,

I have a situation like this,

I have four tables,
1. work_category => work is belong to a category
2. work => the work table
3. budget => the budget table
4. budget_detail => contains work (one to many relationship with work)

I want to make a modelform to handle the entry of budget_detail, instead of add one detail at a time, I want user to just click a work_category, then all works belong to selected category will be displayed, so that user only need to entry the quantity. But I do not want to save all works in budget_detail. during the saving process, I will only save those that are not 0. How can I achieve this?

My current solution is to store all works as entry in budget_detail. This is becoming slow and take huge amount of database space when the work table is growing.

TIA

Daniel
0

#2 User is offline   chiku 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 21-October 17

Posted 06 November 2017 - 01:37 AM

Hello Daniel,

You can view your Work categories in a dropdown using any dropdown method.
Example:

<?php 
     echo $form->field($model, 'work_id')->widget(Select2::classname(), [
        'data' => $workCategoryList,
        'language' => 'en',
        'pluginOptions' => [
            'allowClear' => false,
            'placeholder' => $model->getAttributeLabel('work_id'), 
        ],
    ]); ?>


you can just add Work id and the quantity in your budget detail table. When you need it you can get the work detail from work table using work_id.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users