I want to load model's index page inside tab. I have read yii2 tab document but didn't find suitable example for my case.
My Tab code.
<?php
echo Tabs::widget([
'items' => [
[
'label' => 'Actual Timeline',
$searchModel = new ActualTimelineSearch(),
$dataProvider = $searchModel->search(Yii::$app->request->queryParams),
'content' => $this->render ('index' ,[
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]),
'active' => true
],
[
'label' => 'Fixed Task',
$searchModel = new FixedTaskSearch(),
$dataProvider = $searchModel->search(Yii::$app->request->queryParams),
'content' => $this->render ('index' ,[
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]),
],
],
]);
?>
From this code I am getting This site can’t be reached Error.
My Answer:
You can load a model's index page inside a tab in Yii2 by using the `yii\bootstrap\Tabs` widget along with `yii\bootstrap\Tab` widget. Here's an example code snippet to achieve this:
php
use yii\bootstrap\Tabs;
use yii\bootstrap\Tab;
echo Tabs::widget([
'items' => [
[
'label' => 'Model Index',
'content' => $this->render('_index', ['model' => $model]),
'active' => true,
],
[
'label' => 'Tab 2',
'content' => 'Content for Tab 2',
],
[
'label' => 'Tab 3',
'content' => 'Content for Tab 3',
],
],
]);
In the above code snippet, `_index` is the view file for the model's index page. You can pass the model data to the view file using the `render` method.
Make sure to replace `'Content for Tab 2'` and `'Content for Tab 3'` with the actual content you want to display in those tabs.
Hope this helps! Let me know if you have any further questions.
Rate this post
5 of 5 based on 8000 votesComments