Welcome Guest, Not a member yet? Register   Sign In
How to link image with anchor function
#12

[eluser]Eason[/eluser]
[quote author="elaniobro" date="1268211009"][quote author="Eason" date="1253874144"]Here is my version of anchor_img() function:

Code:
/**
* @param    string   identical to the 1st param of anchor()
* @param    mixed    identical to the 3rd param of anchor()
* @param    string   the path to the image; it can be either an external one
*                    starting by "http://", or internal to your application
* @param    mixed    image attributes that have similar structure as the 3rd param of anchor()
* @return   string
*
* Example 1: anchor_img('controller/method', 'title="My title"', 'path/to/the/image.jpg', 'alt="My image"')
* Example 2: anchor_img('http://example.com', array('title' => 'My title'), 'http://example.com/image.jpg', array('alt' => 'My image'))
*/

function anchor_img($uri = '', $anchor_attributes = '', $img_src = '', $img_attributes = '')
{
    if ( ! is_array($uri))
    {
        $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
    }
    else
    {
        $site_url = site_url($uri);
    }

    if ($anchor_attributes != '')
    {
        $anchor_attributes = _parse_attributes($anchor_attributes);
    }
    
    if (strpos($img_src, '://') === FALSE)
    {
        $CI =& get_instance();
        $img_src = $CI->config->slash_item('base_url').$img_src;
    }
    
    if ($img_attributes != '')
    {
        $img_attributes = _parse_attributes($img_attributes);
    }

    return '<a href="'.$site_url.'">'.'<img src="'.$img_src.'" />'.'</a>';
}

To make it works, this function should be placed in system/helpers/url_helper.php or system/application/helpers/MY_url_helper.php[/quote]


So I put this code into the system/helpers/url_helper.php on line 220 right after the anchor popup function.

I tried using this line of code but nothing is showing up on my site:
Code:
&lt;?= anchor_img('/resume/download',array('src'=>'img/resume/resume_dl.gif','border'=>'0'),'testing image') ?&gt;
[/quote]

Try:
Code:
&lt;?= anchor_img('/resume/download', array(), 'img/resume/resume_dl.gif', array('border'=>'0', 'alt' => 'testing image')) ?&gt;
And check the output html to verify the path to the image.


Messages In This Thread
How to link image with anchor function - by El Forum - 11-18-2008, 05:25 AM
How to link image with anchor function - by El Forum - 11-18-2008, 05:56 AM
How to link image with anchor function - by El Forum - 11-18-2008, 06:36 AM
How to link image with anchor function - by El Forum - 11-19-2008, 01:01 AM
How to link image with anchor function - by El Forum - 11-19-2008, 01:53 AM
How to link image with anchor function - by El Forum - 11-19-2008, 01:54 AM
How to link image with anchor function - by El Forum - 11-19-2008, 02:17 AM
How to link image with anchor function - by El Forum - 06-01-2009, 01:21 PM
How to link image with anchor function - by El Forum - 09-24-2009, 11:22 PM
How to link image with anchor function - by El Forum - 03-09-2010, 08:50 PM
How to link image with anchor function - by El Forum - 03-09-2010, 09:09 PM
How to link image with anchor function - by El Forum - 03-09-2010, 09:20 PM
How to link image with anchor function - by El Forum - 03-09-2010, 09:24 PM
How to link image with anchor function - by El Forum - 03-09-2010, 09:36 PM
How to link image with anchor function - by El Forum - 03-09-2010, 09:51 PM
How to link image with anchor function - by El Forum - 03-09-2010, 11:23 PM
How to link image with anchor function - by El Forum - 03-09-2010, 11:29 PM
How to link image with anchor function - by El Forum - 03-10-2010, 12:03 AM
How to link image with anchor function - by El Forum - 03-10-2010, 12:05 AM
How to link image with anchor function - by El Forum - 03-10-2010, 12:17 AM
How to link image with anchor function - by El Forum - 03-10-2010, 12:22 AM
How to link image with anchor function - by El Forum - 03-10-2010, 12:44 AM
How to link image with anchor function - by El Forum - 03-10-2010, 09:10 AM
How to link image with anchor function - by El Forum - 03-10-2010, 02:00 PM
How to link image with anchor function - by El Forum - 03-10-2010, 02:13 PM
How to link image with anchor function - by El Forum - 03-10-2010, 02:18 PM
How to link image with anchor function - by El Forum - 03-10-2010, 11:05 PM
How to link image with anchor function - by El Forum - 03-29-2010, 07:14 AM
How to link image with anchor function - by El Forum - 12-02-2010, 08:38 PM
How to link image with anchor function - by El Forum - 12-03-2010, 12:25 AM
How to link image with anchor function - by El Forum - 02-23-2011, 09:52 AM
How to link image with anchor function - by El Forum - 04-05-2011, 05:16 PM



Theme © iAndrew 2016 - Forum software by © MyBB