Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何正确调用CHtml::image?_Php_Yii - Fatal编程技术网

Php 如何正确调用CHtml::image?

Php 如何正确调用CHtml::image?,php,yii,Php,Yii,这是我的密码 <?php echo CHtml::image(Yii::app()->request->baseUrl.'/images/Images/phone.png', array('class'=>'ph1'));?> 我在代码执行时出错: htmlspecialchars()要求参数1为字符串,数组给定 错误是什么?这是因为您添加了htmlOptions数组作为第二个参数,而此参数是为图像的备选文本保留的。检查: 公共静态字符串映像(字符串$src,

这是我的密码

<?php echo CHtml::image(Yii::app()->request->baseUrl.'/images/Images/phone.png', array('class'=>'ph1'));?>

我在代码执行时出错:

htmlspecialchars()要求参数1为字符串,数组给定


错误是什么?

这是因为您添加了htmlOptions数组作为第二个参数,而此参数是为图像的备选文本保留的。检查:

公共静态字符串映像(字符串$src,字符串$alt='',数组 $htmlOptions=array())

Sou您需要指定alt参数,例如:

<?php echo CHtml::image(
    Yii::app()->request->baseUrl.'/images/Images/phone.png', 
    '', // this is alt parameter; add text or leave it as empty string
    array('class'=>'ph1')
);?>

这是因为您添加了htmlOptions数组作为第二个参数,而此参数是为图像的备选文本保留的。检查:

公共静态字符串映像(字符串$src,字符串$alt='',数组 $htmlOptions=array())

Sou您需要指定alt参数,例如:

<?php echo CHtml::image(
    Yii::app()->request->baseUrl.'/images/Images/phone.png', 
    '', // this is alt parameter; add text or leave it as empty string
    array('class'=>'ph1')
);?>

根据您错过的
alt
属性:

<?php echo CHtml::image(Yii::app()
  ->request->baseUrl . '/images/Images/phone.png',
  'alt text', 
  array('class'=>'ph1'));
?>

公共静态字符串映像(字符串$src,字符串$alt='',数组 $htmlOptions=array())

根据您错过的
alt
属性:

<?php echo CHtml::image(Yii::app()
  ->request->baseUrl . '/images/Images/phone.png',
  'alt text', 
  array('class'=>'ph1'));
?>

公共静态字符串映像(字符串$src,字符串$alt='',数组 $htmlOptions=array())


上面的错误告诉你做错了什么上面的错误告诉你做错了什么