CakePHP相当于html代码

时间:2012-07-08 13:14:56

标签: php html cakephp twitter-bootstrap

我正在开发一个cakePHP项目,我需要使用PHP创建一个删除数据库中的条目的按钮,但我想在所述按钮上显示twitter bootstrap垃圾桶图标。

包含来自twitter bootstrap的图标的代码是;

<i class="icon-trash"></i>

我需要它的PHP代码是;

<?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']
));?>

有没有人知道如何在这个PHP代码中实现html,所以我可以用图标替换文本'Delete'?

2 个答案:

答案 0 :(得分:3)

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使CakePHP显示未转义的HTML。

如果只是将icon-trash类添加到链接中,它可能(取决于CSS)也可以工作。

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']
));

答案 1 :(得分:1)

首先,如果您正在使用CakePHP和Twitter Bootstrap,那么有一个很棒的帮助程序插件可以让您的生活更轻松https://github.com/loadsys/twitter-bootstrap-helper

然后看按钮方法。我很确定你可以传递'icon'=&gt;参数数组中的'iconname'