2013-10-06 35 views
1

我正在使用CakePHP构建我的应用程序。我想的btn btn-primary btn-sm添加一个类名的<a>在CakePHP中添加类名称

我的代码为元素如下:

<?php echo $this->Form->postLink(
    'Add to cart', 
    array('action' => 'add', $inventory['Inventory']['id']), 
    array('confirm' => 'Are you sure?'), 
    array('class' => 'btn btn-primary btn-sm')); 
?> 

这将导致生成的代码为:

<a href="#" onclick="if (confirm(&quot;Are you sure?&quot;)) { document.post_5250d38671023789772963.submit(); } event.returnValue = false; return false;">Add to cart</a> 

我有尝试将类数组作为第一个数组,中间数组和最后一个数组,它们都有自己的一组问题。从上面的代码中可以看出,它目前设置的方式不会遵守类名。

我需要做些什么来解决这个问题?请帮忙。

回答

1

采取食谱 看看postLink DOC它解释为postLink

FormHelper::postLink(string $title, 
        mixed $url = null, 
        array $options = array(), 
        string $confirmMessage = false) 

所以您的代码修改后的版本可以写成

<?php echo $this->Form->postLink('Add to cart', 
            array('action' => 'add', $inventory['Inventory']['id']), 
            array('class' => 'btn btn-primary btn-sm'), 
           'Are you sure?'); 
?>