如果我不使用 blade 或任何模板,如何使用 href 标签重定向到 laravel 5 中的路由?
How to redirect to a route in laravel 5 by using href tag if I'm not using blade or any template?
Route::get('/page','UserController@view page');
是我的路线。
我有一个带有 href 标签的列表,我想重定向到这条路线。
<ul>
<li><a href="">how it works</a></li>
</ul>
我没有使用 blade 或任何其他模板。
在您的应用配置文件中,将 url
更改为 localhost/example/public
然后当你想 link 做某事时
<a href="{{ url('page') }}">Some Text</a>
没有blade
<a href="<?php echo url('page') ?>">Some Text</a>
除了@chanafdo 回答,你还可以使用路由名称
与 laravel 一起工作时 blade
<a href="{{route('login')}}">login here</a>
路由名称中有参数
当转到 url 时喜欢 URI: profile/{id}
<a href="{{route('profile', ['id' => 1])}}">login here</a>
没有blade
<a href="<?php echo route('login')?>">login here</a>
路由名称中有参数
当转到 url 时喜欢 URI: profile/{id}
<a href="<?php echo route('profile', ['id' => 1])?>">login here</a>
从 laravel 5.2 开始,您可以 use @php @endphp
在 laravel blade 中创建为 <?php ?>
。
使用 blade 您的个人意见,但我建议使用它。学习吧。
它有许多奇妙的功能,如 template inheritance, Components & Slots,subviews 等...
请考虑此解决方案 laravel blade 以编辑列表中的项目
<a href="{{ url('players' , [ 'id' => $player->id ]) }}/edit"
class="btn btn-primary" role="button">Varia</a>
</div>
</div>
@endforeach
Route::get('/page','UserController@view page');
是我的路线。
我有一个带有 href 标签的列表,我想重定向到这条路线。
<ul>
<li><a href="">how it works</a></li>
</ul>
我没有使用 blade 或任何其他模板。
在您的应用配置文件中,将 url
更改为 localhost/example/public
然后当你想 link 做某事时
<a href="{{ url('page') }}">Some Text</a>
没有blade
<a href="<?php echo url('page') ?>">Some Text</a>
除了@chanafdo 回答,你还可以使用路由名称
与 laravel 一起工作时 blade
<a href="{{route('login')}}">login here</a>
路由名称中有参数
当转到 url 时喜欢 URI: profile/{id}
<a href="{{route('profile', ['id' => 1])}}">login here</a>
没有blade
<a href="<?php echo route('login')?>">login here</a>
路由名称中有参数
当转到 url 时喜欢 URI: profile/{id}
<a href="<?php echo route('profile', ['id' => 1])?>">login here</a>
从 laravel 5.2 开始,您可以 use @php @endphp
在 laravel blade 中创建为 <?php ?>
。
使用 blade 您的个人意见,但我建议使用它。学习吧。
它有许多奇妙的功能,如 template inheritance, Components & Slots,subviews 等...
请考虑此解决方案 laravel blade 以编辑列表中的项目
<a href="{{ url('players' , [ 'id' => $player->id ]) }}/edit"
class="btn btn-primary" role="button">Varia</a>
</div>
</div>
@endforeach