简体   繁体   中英

How do I make an image an anchor in CodeIgniter?

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>

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')));

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM