M
M
Maxim Osadchy2018-01-27 14:21:02
Yii
Maxim Osadchy, 2018-01-27 14:21:02

Is it possible to pass sort to select?

Hello!
There are a couple of questions about sorting:
1) There is sorting:

Use yii\data\Sort;
$sort = new Sort([
            'attributes' => [
                'views' => [
                    'label' => 'По популярности',
                ],
                'group1' => [
                    'label' => 'По цене',
                ]
            ],
        ]);

The view is passed like this:
echo $sort->link('group1') . ' | ' . $sort->link('views');

Actually, this is what is described in the docs.
I would like to pass this sort to select like this:
<select>
  <option value="">По цене(по убыванию)</option>
  <option value="">По цене(по возрастанию)</option>
  <option value="">По популярности(по убыванию)</option>
  <option value="">По популярности(по возрастанию)</option>
</select>

How can I do that?
2) For sorting to work, it is necessary to pass orderBy($sort->orders) to my Product::find(), but since not all products have images in the store, my default sorting is as follows: orderBy(['image ' => SORT_DESC]). But if you leave it - sorting does not work, can this problem be solved?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-01-27
@waspmax1

Good afternoon.
Maybe addOrderBy() will help you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question