1

my rules config is:

[
    'pattern' => 'admin/post',
    'route' => 'admin/default/post',
],

it's work! when open http://example.com/admin/post show admin/default/post for me,

but when i want create dynamic url with this code:

echo \yii\helpers\Url::to('/admin/default/test');

output is http://example.com/admin/default/test

who to create a dynamic url correctly?

Muhammad Omer Aslam
  • 22,976
  • 9
  • 42
  • 68
Masoud92m
  • 602
  • 1
  • 8
  • 24

1 Answers1

1

About Url::to()

This method is very similar to [[toRoute()]]. The only difference is that this method requires a route to be specified as an array only. If a string is given, it will be treated as a URL.

You need to pass an array rather than string

\yii\helpers\Url::to(['/admin/default/test']);
Muhammad Omer Aslam
  • 22,976
  • 9
  • 42
  • 68