views:

47

answers:

3

I have read other threads on how to do this and they do not work for me. Can someone tell me how to make an image a anchor in CI?

I have tried these:

<li><?php echo anchor("Home",img("../application/images/Home_up.png")); ?></li>

and

<li><?php echo anchor("Home",img("src"=>"../application/images/Home_up.png")); ?></li>
A: 

There is no native way to make an image anchor. There are some functions that override the anchor() function though, search in the CI forums and wiki.

ign
@Ignacio: not necessarily true. See http://codeigniter.com/forums/viewthread/97297/#492337
stormdrain
You're right. Didn't know the img() function. Your answer is correct then :)
ign
A: 

Have you tried assigning the img function to a variable, and passing that to the anchor function? Something along the lines of:

<?php $img = img('../application/images/Home_up.png'); ?>
<li><?php echo anchor('home', $img); ?></li>

Be sure you have the HTML and URL helpers loaded.

Edit @Dolph and everyone else: This is now TESTED. It WORKS as of 1.7.2.

Perhaps instead of downvoting me, you could have tested it yourself and proved me wrong. Also, I don't see anywhere in his original post anything like the above code. He passed the img function output right into the anchor function - which does not always work. Two functions that spring to mind that wont let you do this are isset and empty. There are many more.

Mike
--; You're just reposting what the OP already tried...
Dolph
See edit inline.
Mike
+1  A: 

With the url helper loaded either via the contoller ($this->load->helper('url');) or via the helper array in /system/application/config/autoload.php; try:

anchor('Home',img(array('src'=>'../application/images/Home_up.png','border'=>'0','alt'=>'Home')));
stormdrain