V
V
VitaliyKaliuzhyn2017-03-31 11:07:52
Yii
VitaliyKaliuzhyn, 2017-03-31 11:07:52

How to set your own ActiveDataProvider parameters?

Good afternoon. The question of such a plan, I display the table, but I do not need the output of the table for everything, I need to weed out the first record.
If you change the offset value in the yii\data\ActiveDataProvider method in the prepareModels method, then everything works, but it’s not ice to change the yii class itself, I created my own inherited, I change the offset, but nothing happens. How can I set the offset?
The method itself

protected function prepareModels()
    {
        if (!$this->query instanceof QueryInterface) {
            throw new InvalidConfigException('The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses.');
        }
        $query = clone $this->query;
        if (($pagination = $this->getPagination()) !== false) {
            $pagination->totalCount = $this->getTotalCount();
            $query->limit($pagination->getLimit())->offset($pagination->getOffset());
        }
        if (($sort = $this->getSort()) !== false) {
            $query->addOrderBy($sort->getOrders());
        }

        return $query->all($this->db);
    }

Or maybe there is an option to set the offset somehow in the view where the table is displayed

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ilya Karavaev, 2017-03-31
@Quieteroks

Instead of it is not simpler to exclude the first record by means of request?
You pass a list of models to the provider (Model::find()), so what prevents you from removing your first entry in the filters of the search itself from the list of models before passing it to the output?

M
Maxim Timofeev, 2017-03-31
@webinar

maybe there is an option to set the offset somehow in the view where the table is displayed

$models = Mymodel::find()->all();
unset($models[0]);

But you have pagination, which makes it unclear the question, how are pagination and the first post related?
Describe the task in more detail.

U
ukoHka, 2017-03-31
@ukoHka

Why don't you use it in a controller? $dataProvider->query->offset(1);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question