0

I created a html site that has images that are links, the images change on mouseover. I use a jquery function for this. It all works perfect in HTML, but Im not sure how to combine the anchor and base_url to them when converting them to codeigniter.

I have been at this all day Id really appreciate any help, I am new to codeigniter I could not find any answers on their page or with a google search.

HTML code (works fine):

<a href="hotel.html">
<img src="img/image.png" hover="img/hoverimage.png" class="rollover"/>
</a>

I can get as far as linking the src image and can apply the class=rollover I just can not figure out how to add the hover="img/hoverimage.png"

<?php echo anchor('hotel', img('img/image.png'), array('class'=>'rollover' ));?>
4

2 回答 2

1

Finally got it working. In short, I had to put the full address of the images rather than calling the base_url within an anchor. Probably a more accurate way of doing it but I spent so much time on this I am just happy it works....

<?php echo anchor('homepg/page/hotel', '<img src="http://localhost/websitefolder/img/image1.png"  hover="http://localhost/websitefolder/img/imagehover.png" class="rollover"/>'); ?>
于 2013-04-04T12:36:05.460 回答
0

First, you don't need to use CodeIgniter's helpers to generate HTML. If you have working HTML already, then use it. Sometimes using CI's helpers can make the code more complicated, especially if other people need to figure out what it's doing.

To answer your question, the img() function accepts an associative array for the image's attributes. So you can specify the attributes similar to the anchor() function.

echo anchor('hotel', img(array('src' => 'img/image.png', 'class' => 'hover', 'hover' => base_url('img/hoverimage.png'))));

Note that this uses the base_url() function from the URL helper.

于 2013-03-30T21:57:11.923 回答