D
D
Dmitry Kim2016-05-15 10:52:52
Yii
Dmitry Kim, 2016-05-15 10:52:52

How to "kosherly" cast the correct URL in Yii2?

What we have:
News model, controller and search model generated via CRUD. The model has a property containing the news category ID.
Further in the view in the list of news, next to the title of each news, there is an "icon" with the name of the category of this news (well, you know how it happens).
It is logical to hang a link to this icon to filter news for a given category. Of course, you can create a separate actionCategoryId that will search for this ID, but it's better to do this through the standard actionIndex. I do like this:

Html::a('Спорт', ['/news/index', (new NewsSearch)->formName().'[category_id]' => $model->category->id]);

Is this kosher, or is there a more concise way to output such a URL? I'm specifically interested in this place:(new NewsSearch)->formName().'[category_id]'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Pavlenko, 2016-05-15
@kimono

This method may help, but not much, in generating the name.
www.yiiframework.com/doc-2.0/yii-helpers-basehtml....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question