Search code examples
csscakephpstylescakephp-2.0bold

Cakephp Adding style to h($product['Product']['name']);


I want to add style to this code:

<?php echo h($product['Product']['name']); ?>

I try to put this way:

<?php echo h($product['Product']['name'], array('style' => 'font-weight:bold;')); ?>

But it give me this error message:

Warning (2): htmlspecialchars() expects parameter 4 to be boolean, array given [CORE\Cake\basics.php, line 199]

can someone tell me the right way to add style to that line.

Thankyou.


Solution

  • h() function is Convenience wrapper for htmlspecialchars() in cakephp. It Convert special characters to HTML entities. So you are getting the warning.

    Syntax for this function is h(string $text, boolean $double = true, string $charset = null)

    To style your code you can use this alternatively

    <?php
    echo $this->Html->tag('span', $product['Product']['name'], array('style' => 'font-weight:bold;'));
    ?>
    // Output
    <span style="font-weight:bold;">Your Product Name</span>