I have a view and I want to make a link that has the current url (with current $_GET parameters) plus one more
Two candinates way to do that are
$this->createUrl('', array('new_param'=>'value-param')) //but generates
Yii::app()->createUrl(CHtml::normalizeUrl(''), array('new_param'=>'value-param')) //but generates
But I want the obvious
I thing I am very closed on this but I cant find out!
Note the old parameters are unkown until the application runs and I don’t want something hacking like that
Yii::app()->request->requestUri . '&new_param=value-param'
$params = array_merge($_GET, array('yourKey1'=>'yourValue1', ...));
It’s pretty ugly, but it does prevent you from duplicating existing keys - they’ll be overridden by your second array.
Although I would like something more yii’s way it will be work.
In this way the extra parameters not repeated again and again among the requests (if the link exists on the other requests)
I thing a problem with this way is the SEO url compatibility with UrlManager… is’t it ?
I think it will work fine for you. What problem do you envisage exactly?
I thought it better and I thing that there is no problem
I hoped there was Yii way to do that and I stuck
This reply is for new people:
$params = Yii::$app->request->getQueryParams() != null ? Yii::$app->request->getQueryParams() : ;
$params = Yii::$app->controller->getRoute();
$params['new_param'] = 'value-param';
After that you can use:
Yii::$app->urlManager->createUrl($params) where you need to create a url.
Yii includes many helpers, like de Url helper, which includes the method
Current that accepts new params.
\yii\helpers\Url::current(['yournewparam' => 'valuefortheparam'])
this is perfect! thank you so much