2015-10-02 139 views
2

我有一个观点event,它有一个额外的动作按钮,重定向到 这里checkin/index页是我的GridView设置页面标题yii2

<?= GridView::widget([ 
    'id'=>'event-table', 
    'dataProvider' => $dataProvider, 
    'filterModel' => $searchModel, 
    'columns' => [ 
     'title', 
     'location', 
     [ 
      'class' => 'yii\grid\ActionColumn', 
      'template' => '{checkin/index} {view} {update} {delete} ', 
      'contentOptions' => ['class'=>'action-td'], 

      'buttons' => [ 
       'checkin/index' => function ($url,$model) { 
        return Html::a('<div id="notification-container"><span data-pjax=false class="glyphicon glyphicon-user"></span>'.EventSearch::showCheckin($model->id) .'</div>', $url,['data-pjax' => true]); 
       }, 
      ] 
     ], 
    ] 
]); 

使用时点击该按钮会打开一个checkin/index 页,所以我想送其上点击按钮,使 的checkin/index页面上,我可以使用该标题$this->title

行的title有任何W AY通过对操作按钮数据点击 这里是我的checkin/index代码

public function actionIndex() 
{ 

    $searchModel = new CheckinSearch(); 
    $dataProvider = $searchModel->search(Yii::$app->request->queryParams); 

    return $this->render('index', [ 
     'searchModel' => $searchModel, 
     'dataProvider' => $dataProvider, 
    ]); 
} 

我不能下面的代码使用的,因为我的$model只会有event_id作为相关表的价值和checkin/index页我用GridView和关系,以显示标题直接使用event.title

$this->title = isset($dataProvider->models[0]->title) ? $dataProvider->models[0]->title : 'empty result'; 
+0

你想通过网址传递数据? –

+0

@InsaneSkulll我只需要设置页面的标题..无论如何我可以...流是这样的...在'事件/索引'行中gridview用户将点击动作列按钮,它会打开'特定记录的checkin/index'页面...所以我想获得用户点击的行的标题并将其传递到下一页以设置页面标题 –

+0

您可以简单地通过url传递数据并让它们打开欲望页面并将其传递给页面标题。 –

回答

2

例如

'buttons' => [ 
    'checkin/index' => function ($model) { 
     return Html::a('<div id="notification-container"><span data-pjax=false class="glyphicon glyphicon-user"></span>', Url::to(['checkin/index', 'title' => $model->title]), $options); 
    } 
], 

在你checkin/index

$this->title => $_REQUSET['title']; 

更多阅读a()to()

+0

再次感谢您的帮助......它帮助..只需修改一下,但解决了我的问题 –

相关问题