Question

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>
Was it helpful?

Solution

I also just found this...

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top