Answer the question
In order to leave comments, you need to log in
How to create a link with get parameters in yii2?
using the string 'http:/bla.com' + params ['foo' => 5, 'bar' => 2]
get 'http:/bla.com?foo=5&bar=2'
Answer the question
In order to leave comments, you need to log in
In yii there is such concept "route" - a route. ( https://github.com/yiisoft/yii2/blob/master/docs/g... ) It contains a link to the controller\action + parameters. Written as an array ['/controller/action', 'param1' => 'val1', 'param2' => 'val2'].
Most methods (the same Html::a) can accept this route as a URL, and Yii will already generate normal URLs in accordance with the rules. By default, it shoves the parameters into the query part of the url, that is, you get a url like
http:/bla.com/controller/action?param1=val1¶m2=val2
But you can configure it for anyone, for example, http:/bla.com/controller/action/ val1/val2 In this case, the code with routes does not have to be rewritten.
In general, everything in yii is well thought out and cool. Personally, we always specify urls as routes - this is really very convenient.
Good afternoon.
For example
Html::a('Link',
['controller/action'],
[
'data' => [
'method' => 'post',
'params' => '{"id":'.$model->id.'}'
],
]);
Html::a('Link',
['controller/action' . $model->id],
);
Html::a('Link',
Url::toRoute(['product/view', 'id' => 42, 'name' => 'name', 'id_s' => 2]));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question