【问题标题】:create dynamic url in yii2在 yii2 中创建动态 url
【发布时间】:2018-05-08 21:32:37
【问题描述】:

我的规则配置是:

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

成功了!当我打开http://example.com/admin/post 时显示admin/default/post

但是当我想用这段代码创建动态网址时:

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

输出是http://example.com/admin/default/test

谁来正确创建动态网址?

【问题讨论】:

    标签: yii2 yii2-basic-app yii2-urlmanager


    【解决方案1】:

    关于Url::to()

    此方法与[[toRoute()]] 非常相似。唯一的区别是 这个方法 只需要将路由指定为数组。如果给出一个字符串,它将被视为一个 URL。

    你需要传递一个array而不是字符串

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

    【讨论】:

      猜你喜欢
      • 2015-03-15
      • 2021-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多