使用 Laravel 链接到页面上的特定锚点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24275667/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
link to specific anchor on a page with Laravel
提问by kash101
How does one go about linking to a specific id in a view with Laravel?
如何使用 Laravel 链接到视图中的特定 id?
My controller:
我的控制器:
public function services() {
return View::make('services.custom_paint', array('pageTitle' => 'Custom Paint'))->with('default_title', $this->default_title);
}
My route:
我的路线:
Route::get('/custom_paint', 'PagesController@services');
I have tried to add #id
to the route, to the controller, and even to the view's URL::to
. Nothing seems to work.
我试图添加#id
到路由、控制器,甚至视图的URL::to
. 似乎没有任何效果。
I assumed that simply adding the id on to the URI would do the trick, but clearly I am missing something.
我认为简单地将 id 添加到 URI 就可以解决问题,但显然我遗漏了一些东西。
回答by lieroes
// Controller
Route::get('/custom_paint', array('as' => 'custom_paint', 'uses' => 'PagesController@services'));
// View
<a href="{{ URL::route('custom_paint') }}#id">LINK</a>
Try this code ;) hope it works..
试试这个代码 ;) 希望它有效..
回答by Bikal Basnet
回答by Elshan
If you pass id to controller as parameter and need to point to correct result with #id
如果您将 id 作为参数传递给控制器并且需要使用 #id 指向正确的结果
<a href="{{ route('custom_paint',['id'=>'$id_value','#id']) }}">Try</a>
I assume above will render as http://localhost/custom_paint/id=123#id
Or Just point to ID:
或者直接指向 ID:
<a href="{{ route('custom_paint',['#id']) }}">Try</a>
I assume above will render as http://localhost/custom_paint/#id
我假设上面将呈现为http://localhost/custom_paint/#id