0

In my Index I need to show the results of two different Tables that are not linked by any relation. I've done that by using two different search models

/* @var $searchModel app\modules\book\models\BookNewSearch */
/* @var $searchModelOld app\modules\book\models\BookOldSearch */

So I have two tabs, with two Gridview each one showing results of one table correctly.

I'm using a module. So my path is module/book/views/book-old and module/book/views/book-new And inside those folder the php files for the view are

view-old.php

and

view-new.php

Problems comes with button and controller used in ActionColumn. I need one "tab" use one controller (with different links too) and the other one use another controller (always different links).

Inside ActionColumn I tried

                            ['class' => 'yii\grid\ActionColumn',
                             'controller' => 'bookold',

It add 'boookold' to the start of the path of the url. But it gaves me Page 404 not found. I've tried also with

'buttons' => [
  'view' => function ($url, $model) {
   return Html::a('<span class="glyphicon glyphicon-eye-open"></span>',
   Yii::$app->urlManager->createUrl([Yii::$app->controller->id.'/view-old',
                                                'id' => $model->id]),
                                  ['title' => Yii::t('yii', 'Details'),]);
                                    }],

but Yii::$app->controller->id return the same default controller. How should i proceed?

To be concise I need to change the last part of the url (view-old and view-new) and to change the controller. My controller is like this:

public function actionIndex()
{
    $searchModel = new BookNewSearch();
    $searchModelOld = new BookOldSearch();
    $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
    $dataProviderOld = $searchModelOld->search(Yii::$app->request->queryParams);

    return $this->render('index', [
        'searchModelOld' => $searchModelOld,
        'searchModel' => $searchModel,
        'dataProvider' => $dataProvider,
        'dataProviderOld' => $dataProviderOld,
    ]);
}
Arcanis
  • 31
  • 1
  • 5

1 Answers1

0

Try this in your each grid view:

   [  
    'class' => 'yii\grid\ActionColumn',
    'contentOptions' => ['style' => 'width:260px;'],
    'header'=>'Actions',
    'template' => '{view} {delete}',
    'buttons' => [

        //view button
        'view' => function ($url, $model) {
            return Html::a('<span class="fa fa-search"></span>View', $url, [
                        'title' => Yii::t('app', 'View'),
                        'class'=>'btn btn-primary btn-xs',                                  
            ]);
        },
    ],

    'urlCreator' => function ($action, $model, $key, $index) {
        if ($action === 'view') {
            $url ='/controller/view?id='.$model->id;
            return $url;
        }
    }

   ],
Muhammad Shahzad
  • 9,340
  • 21
  • 86
  • 130