_pocra
(Robbie)
May 3, 2010, 7:35pm
1
Hello,
I have (I hope so) a simple question…
How do I create a link with an image?
The normal way is so:
<?php echo CHtml::link([some HTML], array('view', 'id'=>$data->id)); ?>
The problem is the following:
The pictures I’d like to show are saved on my server, the path is saved in a mySQL-Database.
Here is the structure:
id int(11) auto_increment
picturenumber int(11) -> imagename on the server
gallery int(11) -> FK to another table (at the moment not relevant)
portfolio bool
How the pictures are stored:
server/gallery/[gallery] /[picturenumber] .jpg
And now the big question…
What have I to insert in the server/protected/views/gallery/_view.php?
It must be something like this
<?php echo CHtml::link(<img src=“gallery/”$data->gallery /th_$data->picturenumber .jpg" alt="$data->picturenumber .jpg" />, array(‘view’, ‘id’=>$data->id)); ?>
And the output must be like this:
<a href="server/index.php?r=pictures/view&id=[id]">
<img src="server/gallery/[$data->gallery]/[$data->picturenumber].jpg" alt="[$data->picturenumber]">
</a>
[size=“4”]Thanks in advance! [/size]
mdomba
(Maurizio Domba Cerin)
May 4, 2010, 9:02am
2
You answered yourself, just have to use appropriate apostrofe…
echo CHtml::link('<img src="server/gallery/'.$data->gallery.'/th_'.$data->picturenumber.'.jpg" alt="'.$data->picturenumber.'.jpg" />', array('view', 'id'=>$data->id));
or for more Yii way
$imghtml=CHtml::image('server/gallery/'.$data->gallery.'/th_'.$data->picturenumber.'.jpg', $data->picturenumber.'.jpg');
echo CHtml::link($imghtml, array('view', 'id'=>$data->id));
zibams
(Zibamstereo)
February 11, 2012, 7:45pm
4
That works perfect!
Thanks!
Please am building a simple student record management system. furthermore, i want to use an image as a link to my log in page on my web application. tried using the default "img src" tag which i know is wrong so how do i go about it. i created my web application using the Yiic tool so my image is already in images folder. please help
thanks.
jacmoe
(Jacob Moena)
February 11, 2012, 7:56pm
5
The answer is spelled out in one of the previous posts - what seems to be the problem?
zibams
(Zibamstereo)
February 15, 2012, 8:55pm
6
I reckon you were refering to pocra’s reply. would try it now an give you some feedback.
Cheers
jacmoe
(Jacob Moena)
February 15, 2012, 9:00pm
7
Mdomba spelled it out in two ways.
econesa
(Econesa)
April 8, 2013, 4:49pm
8
What about CHtml:link with an image and a confirm message?
I tried it but there is something wrong:
$image = CHtml::image( 'images/x.png', 'Delete', array('title'='Delete'));
echo CHtml::link($image, '#', array('confirm' => 'Are you sure you want to delete this item?'));