Gilko
Gilko

Reputation: 2387

cakePHP 3.0 and bootstrap glyphicons

I want to add glyphicons instead of text in my index, add, edit views.

This works in the index.ctp

<?= $this->Html->link(__('<i class="glyphicon glyphicon-pencil"></i>'), ['action' => 'edit', $user->user_id], array('escape' => false)) ?>

But when I do it for the delete action it shows me the glyphicon but it doesn't give me the 'Are you sure you want to delete the user?' anymore

<?= $this->Form->postLink(__('<i class="glyphicon glyphicon-minus"></i>'), ['action' => 'delete', $user->user_id], array('escape' => false), ['confirm' => __('Are you sure you want to delete {0}?', $user->username)]) ?>

In the view.ctp it breaks the code that comes after so the content that comes after isn't shown. (in this example that's the content after the glyphicon-pencil. The glyphicon-pencil itself isn't shown as well.

<?= $this->Html->link(__('<i class="glyphicon glyphicon-pencil'), ['action' => 'edit', $user->user_id], ['escape' => false]) ?> 

Upvotes: 0

Views: 1484

Answers (1)

ndm
ndm

Reputation: 60463

Take a closer look at the arguments that you are passing, you are passing 4, where the method only accepts 3, ie the confirm option is not passed in the actual options argument.

Proper formatting helps a lot to spot such mistakes.

<?=
$this->Form->postLink(
    __('<i class="glyphicon glyphicon-minus"></i>'),
    [
        'action' => 'delete',
        $user->user_id
    ],
    [
        'escapeTitle' => false,
        'confirm' => __('Are you sure you want to delete {0}?', $user->username)
    ]
)
?>

And your FormHelper::link() example is missing a closing double quote for the <i> elements class attribute, as well as a closing tag for the element itself:

'<i class="glyphicon glyphicon-pencil"></i>'

Also you may want to use escapeTitle instead of escape, in order to avoid disabling escaping for attributes too.

Upvotes: 4

Related Questions