Reputation: 2097
I am working on a cakePHP project and I need to create a button using PHP that will delete an entry in a database, but I want to display the twitter bootstrap trashcan icon on said button.
The code to include the icon from twitter bootstrap is;
<i class="icon-trash"></i>
And the PHP code I need it to work in is;
<?php echo $this->Form->postLink(__('Delete'),
array(
'action' => 'delete',
$skill['Skill']['SkillID']),
array(
'class'=>'btn'),
null,
__('Are you sure you want to delete # %s?',
$skill['Skill']['SkillID']
));?>
Does anyone know how to implement the html in this PHP code so I can replace the text 'Delete' with the icon?
Upvotes: 1
Views: 1197
Reputation: 1245
Firstly, if you're using CakePHP and Twitter Bootstrap, there is a great helper plugin which will make your life easier https://github.com/loadsys/twitter-bootstrap-helper
Then look at the button method. I'm pretty sure you can just pass it an 'icon' => 'iconname' in the parameters array
Upvotes: 1
Reputation: 33163
echo $this->Form->postLink(
'<i class="icon-trash"></i> '.__('Delete'),
array(
'action' => 'delete',
$skill['Skill']['SkillID']
),
array(
'class'=>'btn',
'escape' => false
),
null,
__('Are you sure you want to delete # %s?',
$skill['Skill']['SkillID'] )
);
'escape' => false
makes CakePHP display the HTML unescaped.
It might (depending on the CSS) also work if you just add the icon-trash
class to the link.
echo $this->Form->postLink(__('Delete'),
array(
'action' => 'delete',
$skill['Skill']['SkillID']),
array(
'class'=>'btn icon-trash'),
null,
__('Are you sure you want to delete # %s?',
$skill['Skill']['SkillID']
));
Upvotes: 3