문제

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