A
A
Alexander Nevsky2018-11-26 07:37:01
Yii
Alexander Nevsky, 2018-11-26 07:37:01

How to remove the model from the url when getting a yii request?

There was already a topic about this, but I didn’t really understand, I tried it, it didn’t work.
The bottom line is this, I want to sort the ListView while putting it in the droplist, but as I understand it, just displaying the listview sorter in the layout will not work normally to put it in the drop. Therefore, I made a separate form, but get comes with the model.
That is, from this "?BooksSearch%5Bsort%5D=number_chapters" you need to make this "?sort=number_chapters".
In general, it is desirable that this get request is simply added to the rest, and not replaced.

$data_sort = [
  'number_chapters' => 'Глав, по возрастанию',
  '-number_chapters' => 'Глав, по убыванию',
];
$params = [
  'prompt' => '--'
];
$form = ActiveForm::begin([
  'action'    => ['index'],
  'method'    => 'get',
  'id' => 'sortForm',
]);
  $form->field($sort, 'sort', ['template' => '{input}'])->dropDownList($data_sort, $params);
  Html::submitButton('Сортировать', [/*'class' => 'd-none'*/])
ActiveForm::end();

$this->render('_sort', [
  'sort' => $searchModel,
]);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question