Bibash Adhikari
Bibash Adhikari

Reputation: 173

Displaying multiple data in DetailView of yii2 by using the same id

I have a small problem to display multiple data in detailview of yii2.

Let me explain the problem.

enter image description here

This is my search page. Here I have 2 books with same book_id=1. Now, while I am viewing the detail of this record in the view page, I need to display both books' numbers. Acc no is the book number.

Below is my view page:

enter image description here

This is my view page. Now, in Acc No there is only one book number 22478 but 22479 is not displaying.

Let me show you the code of my gridview.

 <?= DetailView::widget([
        'model' => $model,
        'attributes' => [
        'id',
        'book_id',
        'accession_no',
        [
        'format'=>'raw',
        'attribute'=>'title',
        ]

        [
        'format'=>'raw',
        'attribute'=>'title',

        'value' => $model1->language == 1 ? 
        "<p class='n'>" . $model1->title . "</p>" 
         : $model1->title,
       ],

        [
                'format' => 'raw',
                'attribute' => 'qty',


                 'value' => $model1->book_qty,
            ],
  ],
            ]) ?>

I need help as I am new to coding.

Upvotes: 0

Views: 3256

Answers (1)

sm1979
sm1979

Reputation: 290

Please refer to http://www.yiiframework.com/doc-2.0/guide-output-data-widgets.html#detailview

DetailView displays the detail of a single data $model.

DetailView is best used for displaying a model in a regular format (e.g. each model attribute is displayed as a row in a table.) The model can be either an instance of yii\base\Model or an associative array.

So basically what you are trying to do is not possible using DetailView.

You should try looking into using Yii2 ListView to solve your requirements.

Upvotes: 1

Related Questions