Mic*_*res 4 php laravel blade laravel-4 laravel-routing
我正在尝试创建一个带有别名数组的路由,所以当我调用whois或who_is在url中它会转到相同的路径.
然后我不需要每次都重复代码,只更改别名.
我试过下面的代码.
路线中的变量:
$path = 'App\Modules\Content\Controllers\ContentController@';
$aliases['whois'] = '(quemsomos|who_is|whois)';
Run Code Online (Sandbox Code Playgroud)
路线:
Route::get('{whois}', array('as' =>'whois', 'uses' => $path.'getWhois'))->where('whois', $aliases['whois']);
Run Code Online (Sandbox Code Playgroud)
这个也适用
Route::get('{whois}', $path.'getWhois')->where('whois', $aliases['whois']);
Run Code Online (Sandbox Code Playgroud)
在输入网址my_laravel.com/whois或my_laravel.com/who_is或my_laravel.com/quemsomos会送我去$path.'getWhois' (这是正确的).
但是当我尝试在刀片上的html中调用它时...
<a href="{{ route('whois') }}">Who we are</a>
Run Code Online (Sandbox Code Playgroud)
参考链接转到 my_laravel.com//%7Bwhois%7D
我怎样才能调用route('whois')我的blade.php并让它像我在网址上输入一样工作?
我想route在我的刀片中使用函数`,所以我可以保留一个模式.
在使用该route函数生成路径期间,Laravel期望您设置route参数的值.您将参数whois留空,因此参数捕获{whois}将不会被替换,并且会产生%7B和&7D奖励.
因此,为了生成路线,您需要定义您想要用于whois的值; {{ route('whois', ['whois'=>'whois']) }}例如.
| 归档时间: |
|
| 查看次数: |
2216 次 |
| 最近记录: |