-1

I have two different tables:

document_master

doc_id

cat_id

doc_name

category_master

cat_id

cat_name

cat_desc

I want cat_name in dropdown of view file document model. I have created model called catmodel which contains details of category_master. I have also created model of docmodel as well.

How I get category name in dropdown in view?

vijay nathji
  • 1,608
  • 13
  • 23

2 Answers2

2

From what I understand is that, you will show the category dropdown based on the selected document. Am I correct?

If that so, you will need to query the categories based on the cat_id from the document model. I assume cat_id is a reference to document table.

You can use something like this,

$query = new Query;
$query->select(['category.*'])
->from('category')
->leftJoin('document', 'category.cat_id = document.cat_id');

The code above queries all the categories with cat_id equal to selected document cat_id.

Hope this helps!

Jake
  • 135
  • 1
  • 11
0
step :1

Create a function in category module file

public function getcategories()
{
        return ArrayHelper::map(DocCatogories::find()->all(), 'catogory_id', 'catogory_name');
}

step :2

Create a function in category module or
public function getcategories(){
return array();
}


step :3
Write a following code for auto fill up drop down list in document view file.

<div class = "form-group">
        <label class = "col-sm-3 control-label" for = "catogory_id">Select Category</label>
        <div class = "col-sm-9">
            <?php
                $categories = new DocCatogories;
                echo $form->field($model, 'catogory_id')->dropDownList($categories->getcategories())->label(false);
            ?>
        </div>
</div>
vijay nathji
  • 1,608
  • 13
  • 23