Sunday, February 27, 2022

[FIXED] how to show 2 form from same table in search

Issue

I want to ask, how to show 2 forms from the same table with a related table in yii2,

example

<?php
    $label1 = app\models\AppFieldConfigSearch::getLabelName(Location::tableName(), "Location");
    ?>
    <?= $form->field($model, 'id_location')->label($label1) ?>


    <?php
        $label1 = app\models\AppFieldConfigSearch::getLabelName(LocationUnit::tableName(), "label1");
    ?>
    <?= $form->field($model, 'label1')->label($label1) ?>

    <?php $dataListAssetMaster2 = ArrayHelper::map(Owner::find()->asArray()->all(), 'id_owner', 'name');
    echo $form->field($model, 'id_owner')->widget(Select2::classname(), [
        'data' => $dataListAssetMaster2,
        'pluginOptions' => [
            'allowClear' => true
        ],
        'options' => [
            'prompt' => 'Pilih Nama']
    ])->label("Name");
    ?>
    <?php $dataListAssetMaster4 = ArrayHelper::map(Location::find()->asArray()->all(), 'id_location', 'address');
    echo $form->field($model, 'id_location')->widget(Select2::classname(), [
        'data' => $dataListAssetMaster4,
        'pluginOptions' => [
            'allowClear' => true
        ],
        'options' => [
            'prompt' => 'Status Pembebasan']
    ])->label("location address");

// my search model

public function rules()
{
    return [
        [['id_location_unit', 'id_location', 'id_owner','id_mst_status1'], 'integer'],
        [['label1', 'label2', 'label3', 'keterangan1', 'keterangan2', 'keterangan3','address'], 'safe'],
    ];
}

I want to display the same 2 tables on 1 search form, but I have a problem when I use the code, one of the forms does not appear


Solution

You can combine 2 of your model/form into 1 search model. Let your search model decide on the search logic.



Answered By - Godzilla

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.