Laravel Classroom image

osdyui
 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2|
Lessons:-Links and URLs

Generating Links
Now that we can retrieve our site URLs, the next logical step would be to use them to create
hyper-links. Now I know what you’re thinking, we can do it like this..
1 <a href="<?php echo URL::to('my/page'); ?>">My Page</a>
Sure that would work, but it’s a little ugly. In Laravel if something is a little ugly, there is always
a better way of handling it. Links are no exception.
Why don’t we use the HTML class to generate a link? After all, that’s what the HTML class is
for. It is used to generate all kinds of HTML tags.
1 <?php echo HTML::link('my/page', 'My Page'); ?>
That looks a lot better! Let’s see the result.
1 <a href="http://myproject/my/page">My Page</a>
If you are an SEO ninja, and cannot stand to see a link without a title attribute, simply pass an
extra array.
1 <?php echo HTML::link('my/page', 'My Page', array('title' => 'My page!')); \
2 ?>
Which gives..
1 <a href="http://myproject/my/page" title="My page!">My Page</a>
One of the great features of Laravel is how consistent its method naming is. Many of the
HTML::link methods follow a similar naming pattern as the URL::to methods, which makes
them easy to remember. Let’s take a look at how we can link to a secure page (via HTTPS).
1 <?php
2
3 HTML::link_to_secure('my/page', 'My Page');
4 // <a href="https://myproject/my/page">My Page</a>
Links and URLs 24
We can also use link_to_route to create a link to a named route just like we did with the URL
library.
1 <?php
2
3 HTML::link_to_route('login', 'Login!');
4 // <a href="http://myproject/login/page">Login!</a>
Once again we can use the link_to_action() method to link to a controller-action pair, for
example..
1 <?php
2
3 HTML::link_to_action('account@login', 'Login!');
4 // <a href="http://myproject/account/login">Login!</a>
Laravel even gives us a method of easily creating ‘mailto’ links from an email address. Let’s take
a look.
1 <?php
2
3 HTML::mailto('me@daylerees.com', 'Mail me!');
4 // <a href="mailto:me@daylerees.com">Mail me!</a>
Nice and clean!
Now that you know how to create URL’s and links, your applications will start to grow in size,
covering many routes until they consume our planet and take over the unive…
Your applications will be a lot more interesting!

 
 
 

osdyui

Skills    Laravel

Qualifications :-
Location :-,,,
Description:-
Explore
 

  Students (0)