简体   繁体   中英

Using bootstrap glyphicon in Laravel url

I'm new with Laravel framework and would like to make a simple CRUD application. Everything is worked, but I have a little problem with Bootstrap's glyphicon.

First, i have this code for my 'Delete' button, which has modal confirmation shown before deleting data.

{{ link_to_action('BookController@delete', 'Delete', array($book->id),
   array('class' => 'btn btn-danger delete-event', 'data-title'=>'Confirm',
   'data-content' => 'Are you sure to delete?',
   'onClick'=>'return false;'))
}}

which is similiar to call a modal form using JQuery:

 <a href='/delete/' class='btn btn-danger' data-title='Confirm' data-content='Are you sure?'>
    Delete</a>

I would like to know how to use glyphicon in this url which is usually be like

 <a href='/delete/' class='btn btn-danger' data-title='Confirm' data-content='Are you sure to delete?'>
 <i class='glyphicon glyphicon-trash'></i>Delete</a>

Any idea how to do it? Thanks in advance.

Just create the link manually

<a href="{{ action('BookController@delete', [$book->id]) }}"
   class="btn btn-danger" data-title="Confirm" data-content="Are you sure?">
    <i class="glyphicon glyphicon-trash"></i>Delete</a>

Passing the title as a string does not help, because the title is being converted to htmlentitiies:

/**
 * Convert an HTML string to entities.
 *
 * @param  string  $value
 * @return string
 */
public function entities($value)
{
    return htmlentities($value, ENT_QUOTES, 'UTF-8', false);
}

What you can do is register you own HTML Macro: Register HTML Macro

HTML::macro('sumthin', function($actionName, $params, $title, $attributes)
{
    return '<a href="' . action($actionName, $params) . '" title="" >' . $title . '</a>';
});

Then you can use it from you views in a similar way:

{{ HTML::sumthin('HomeController@index',
    array(/* params */),
    '<i class="glyphicon glyphicon-trash"></i>',
    array('class' => 'btn')) }}

The sample above is untested but just as a reference to show the idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM