문제

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