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.

有帮助吗?

解决方案

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>

其他提示

the simple way is:

<b><?php echo h($product['Product']['name']); ?></b>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top