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,
]);
}