Yii框架中的图片链接 [英] image link in Yii framework

查看:29
本文介绍了Yii框架中的图片链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,我是 YII 的新手.我有一个图像.在 Yii 中调用该图像后,其代码如下

hello friends I am newbie to YII. I have an image . After calling that image in Yii its code like is this

<img class="deals_product_image" src="<?php echo MPFunctions::uploaded_image_url($data->item_display_image()->file_ufilename); ?>" alt="<?php echo $data->name; ?>" />

在一般的 html 中它是这样做的

in general html it is doing like this

<img alt="women jackets" src="files/items/images/4db3b3b6a7c06/womens-jacket-thumb.jpg" class="deals_product_image">

现在我希望这张图片应该是一个href链接

Now I want that this image should be a href link like

 <a href="files/items/images/4db3b3b6a7c06/womens-jacket-thumb.jpg img src="files/items/images/4db3b3b6a7c06/womens-jacket-thumb.jpg class="deals_product_image"/> </a>

所以为此我使用了这样的代码

so for this I used code like this

<?php echo CHtml::link('', array('items/viewslug', 'slug'=>$data->slug)); ?>

但它没有显示任何链接标签,如 <a href="">那么谁能告诉我该怎么做?我应该在 '' 标签之间写什么?

But it is not showing any link tag like <a href=""> so can any one tell me what should I do?What should I write in between '' tags?

推荐答案

您应该简单地将 <img> 标签的 html 作为第一个参数:

You should simply give the html for the <img> tag as the first parameter:

$imageUrl = MPFunctions::uploaded_image_url($data->item_display_image()->file_ufilename);
$image = '<img class="deals_product_image" src="'.$imageUrl.'" alt="'.$data->name.'" />';

echo CHtml::link($image, array('items/viewslug', 'slug'=>$data->slug));

顺便说一下,您也可以使用 CHtml::image 来创建 标签:

By the way, you can use CHtml::image to create the <img> tag as well:

$imageUrl = MPFunctions::uploaded_image_url($data->item_display_image()->file_ufilename);
$image = CHtml::image($imageUrl, $data->name, array('class' => 'deals_product_image'));

echo CHtml::link($image, array('items/viewslug', 'slug'=>$data->slug));

这篇关于Yii框架中的图片链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆