V
V
Vitaly Liber2015-04-14 08:32:35
Yii
Vitaly Liber, 2015-04-14 08:32:35

How to implement data output by the yii2 LinkPager widget according to a certain criterion?

There is a LinkPager widget and Yii2. The widget displays multiple entries per page. The rest is paginated.
How can I make it show posts only with the selected criteria?
For example, according to the filled field "publication"? If the value is 1, then outputs. If there is no value, then it does not display.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Liber, 2015-04-14
@VitalyLiber

Initially, the paginator code in the controller was like this:

public function actionIndex()
    {

        $query = Orders::find();

        $pagination = new Pagination([
            'defaultPageSize' => 5,
            'totalCount' => $query->count(),
        ]);

        $orderies = $query->orderBy('id')
            ->offset($pagination->offset)
            ->limit($pagination->limit)
            ->all();

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

Added to the controller in the line
Such a line This line
will turn out
Then, in all models, added active. Added an active column to the database.
Now, with a value of 0, which is written to the database when sending, the record does not get into pagination. If you change in the CRUD editor to one, then it is displayed.

A
Alzasr, 2015-04-14
@Alzasr

One of the parameters of the LinkPager widget is DataProvider, in the controller (if you used Gii) it is created as $dataProvider = $searchModel->search(Yii::$app->request->queryParams); you can add your terms.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question