如何在我的gridview中进行查看操作,我已经有了我的数据列表和查看按钮,但是我想在点击该视图按钮时看到不同的记录。现在我只看到错误,我的网址更改为/ index / 0或/ index / 1等记录的id。
<?php
use yii\grid\GridView;
?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
'ID'=>'id',
'Title'=>'post_title',
'Text'=>'post_text',
'Author'=>'name',
[
'class' => 'yii\grid\ActionColumn',
'header'=>'Действия',
'headerOptions' => ['width' => '80'],
'template' => '{view}',
],
],
'rowOptions' => function ($model, $key, $index, $grid) {
return ['id' => $model['id']];
},
]); ?>
我有这个错误:
An Error occurred while handling another error:
exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request: site/error' in W:\XAMPP\htdocs\test\basic\vendor\yiisoft\yii2\base\Controller.php:125
Stack trace:
#0 W:\XAMPP\htdocs\test\basic\vendor\yiisoft\yii2\base\Module.php(454): yii\base\Controller->runAction('error', Array)
#1 W:\XAMPP\htdocs\test\basic\vendor\yiisoft\yii2\web\ErrorHandler.php(93): yii\base\Module->runAction('site/error')
#2 W:\XAMPP\htdocs\test\basic\vendor\yiisoft\yii2\base\ErrorHandler.php(109): yii\web\ErrorHandler->renderException(Object(yii\web\NotFoundHttpException))
#3 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\web\NotFoundHttpException))
#4 {main}
Previous exception:
exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request: site/view' in W:\XAMPP\htdocs\test\basic\vendor\yiisoft\yii2\base\Controller.php:125
Stack trace:
#0 W:\XAMPP\htdocs\test\basic\vendor\yiisoft\yii2\base\Module.php(454): yii\base\Controller->runAction('view', Array)
#1 W:\XAMPP\htdocs\test\basic\vendor\yiisoft\yii2\web\Application.php(100): yii\base\Module->runAction('site/view', Array)
#2 W:\XAMPP\htdocs\test\basic\vendor\yiisoft\yii2\base\Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#3 W:\XAMPP\htdocs\test\basic\index.php(12): yii\base\Application->run()
#4 {main}
Next exception 'yii\web\NotFoundHttpException' with message 'Page not found.' in W:\XAMPP\htdocs\test\basic\vendor\yiisoft\yii2\web\Application.php:112
Stack trace:
#0 W:\XAMPP\htdocs\test\basic\vendor\yiisoft\yii2\base\Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#1 W:\XAMPP\htdocs\test\basic\index.php(12): yii\base\Application->run()
#2 {main}
答案 0 :(得分:0)
您的网站/视图中似乎没有视图名称view.php
确保您的站点控制器中有viewAction
class SiteController extends Controller
{
....
// this is only a sample
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
...
}
yourAppName / views / site /目录中的view.php