Skip to content Skip to sidebar Skip to footer

Cakephp Equivalent Of Html Code

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

Solution 1:

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

Solution 2:

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

Post a Comment for "Cakephp Equivalent Of Html Code"