我不能使用yii框架在视图文件中包含图像
问题描述:
I am new in yii framework. I am trying to include image in view file in yii framework. View file is in admin module,but image is in my root folder. My root folder is 'jobseeker'. Image is in 'images' folder inside jobseeker folder. Name of image is 'update.png'.
My View file's name is list_jobseeker.php
I am including image this way:
<?php echo CHtml::image(Yii::app()->request->baseUrl.'/images/update.png', array('site/job_apply'));?>
I got the error: htmlspecialchars() expects parameter 1 to be string, array given
答
Second parameter in CHtml::image is alt attribute of img element. So your image including code should be something like:
<?php echo CHtml::image(Yii::app()->request->baseUrl.'/images/update.png'
, 'update'); ?>
If you want image to be a link then use CHtml::link with CHtml::image:
<?php $img = CHtml::image(Yii::app()->request->baseUrl.'/images/update.png'
, 'update');
echo CHtml::link($img, Yii::app()->createUrl('site/job_apply'));
?>