Question

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.

Était-ce utile?

La 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>

Autres conseils

the simple way is:

<b><?php echo h($product['Product']['name']); ?></b>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top