In my view I do not want to hardcode a url in just incase I change it... Is there a way to generate the hyperlink url by saying i'm going to use this controller and this action... something like:

<a href = 'echo ActionLink("Logout", "Authentication");'>Logout</a>
有帮助吗?

解决方案

I also just found this...

<a href="<?php echo action('AuthenticationController@Logout'); ?>">Logout</a>

其他提示

What you need to do is to be able to refer to your routes somehow. There are two primary methods of doing this: naming them and referring to a controller action (i.e. Controller@action).

The best and most flexible, however, is to name your routes. This means that if you refactor your controllers (e.g. change the classnames or namespaces), you have to change less code (just where the route points to, rather than where each view reference is).

Whichever way you do it, you can use all sorts of helpers to get what you want. The following are all equivalent:

{{ link_to_route('route.name', 'Title) }}
{{ HTML::linkRoute('route.name', 'Title') }}
<a href="{{{ route('route.name') }}}">Title</a>
<a href="{{{ URL::route('route.name') }}}">Title</a>

Similarly, you can use 'action' in place of 'route' in those helpers to do the equivalent version using the Controller@action way of specifying the route.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top