简体   繁体   中英

pagination button is not working in gridview Yii2

Pagination button is not working in 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). What code I have missed here. Here is my 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. Are you using this GridView inside a view.php file? If yes, the pagination will assume that one as the base URL and you should specify which is the correct URL to use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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