简体   繁体   English

分页按钮在 gridview Yii2 中不起作用

[英]pagination button is not working in gridview Yii2

Pagination button is not working in gridview Yii2.分页按钮在 gridview Yii2 中不起作用。 If I click on page 2 button its moving to other page with URL (http://localhost/testyii/frontend/web/products/view?page=2&per-page=3) and its showing error (404 Not found URL was not found on this server).如果我单击第 2 页按钮,它会移动到带有 URL(http://localhost/testyii/frontend/web/products/view?page=2&per-page=3)的其他页面,并且它的显示错误(404 Not found URL 不是在此服务器上找到)。 What code I have missed here.我在这里错过了什么代码。 Here is my controller:-这是我的 controller:-

public function actionView()
    {
        $WmProducts = WmProducts::find();
        $dataProvider = new ActiveDataProvider ([
            'query' =>$WmProducts,
            'pagination' => ['pageSize'=>3],  
            ]);
        return $this->render('view', [
            'dataProvider' =>$dataProvider]);                     
    }

Here is view page:-这是查看页面:-

<?php
use yii\grid\GridView;
use yii\data\ActiveDataProvider;
use yii\widgets\ActiveForm;
use yii\helpers\Html;
use yii\widgets\Pjax;
use app\models\Client;
?>
<?php
echo GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => [
        'id',
         [
            'attribute' => 'name',
            'format' => 'text'
         ],

         [
            'attribute' => 'wholesale_price',
            'format' => 'text'
         ],
         [
            'attribute' => 'is_retail',
            'format' => 'text'
         ],
         [
            'attribute' => 'distributor_price',
            'format' => 'Text'
         ]

        ]
]);
?>

How to resolve it.如何解决它。 And what I have missed in the view page.以及我在查看页面中错过的内容。

It seems You have modified the pagination component in some way if it is sending you to /view... instead of /index... URL.如果分页组件将您发送到/view...而不是/index... URL,您似乎已经以某种方式修改了分页组件。 Are you using this GridView inside a view.php file?您是否在view.php文件中使用此 GridView ? If yes, the pagination will assume that one as the base URL and you should specify which is the correct URL to use.如果是,分页将假定一个作为基础 URL 并且您应该指定哪个是正确的 URL 使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM