多应用模式下,生成 URL 会带上应用名称,包括我们设置的默认应用也会带上的。
1 2 3 4 5
| public function index() { return (string) url('index/index/index'); }
|
上面的注释是返回的值,可以分析出 URL 是在 index 模块下 index 控制器的 index 方法,可能会觉得有点不美观,目前发现存在三种方案可以修改。
设置应用名称为空字符串
1 2 3 4 5 6 7
| public function index() { $this->app->http->name(''); return (string) url('index/index/index'); }
|
配置文件设置应用映射
config\app.php
1 2 3 4
| 'app_map' => [ '/' => 'index', ],
|
1 2 3 4 5
| public function index() { return (string) url('index/index/index'); }
|
字符串处理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| public function index() { $url = (string) url('index/index/index');
$default_app = config('app.default_app', 'index');
if(strpos($url, '/' . $default_app) === 0) { $url = substr($url, strlen($default_app) + 1); }
return $url; }
|
注意:上面提供的方法,都需要在 config/app.php
配置文件中设置 app_express=true
。