0

I'm trying to create Url with multiple param using Url::to() method but it's not working i also tried UrlManager->creatUrl() method but no luck, i have pretty Url enable and if i use only one query param it works fine but when i try to add more i got error, below is my code.

$linkUrl = \Yii::$app->UrlManager->createUrl(['sell/updatecategory', ['draftId'=> $model->draftId,'catid' =>$model->category_id]]);
<?= Html::button('Change category or product',['value'=>$linkUrl, 'id' => 'StartOver']) ?>
another try is:
$linkUrl = Url::to(['sell/updatecategory', ['draftId'=> $model->draftId,'catid' =>$model->category_id]]);

in the two case above the url output always look like this:

GET http://http://192.168.199.128/trobay/products/sell/updatecategory?1%5BdraftId%5D=20&1%5Bcatid%5D=50

and the server throw an error cannot resolve the url, what i want is something like this:

GET http://http://192.168.199.128/trobay/products/sell/updatecategory?draftId=20&catid=50

The system added some character which i guess is the cause of the problem but don't really know how to remove this. i hot anyone could help with this thanks

1 Answer 1

1

Don't use nested array for parameters. Structure should look like this:

[0 => route, param1 => value1, param2 => value2, ...]

so in your case

$linkUrl = Url::to([
    'sell/updatecategory', 
    'draftId' => $model->draftId, 
    'catid' => $model->category_id
]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.