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

[eluser]elaniobro[/eluser]
[quote author="xwero" date="1227102888"]The problem with the custom functions is that they are limiting the possibilities to generate the a tag as you want. The anchor function doesn't check if the second argument contains no tags so you can do
Code:
anchor('test',img(array('src'=>'admin/images/unpublish.png','border'=>'0','alt'=>'testing image')),array('class'=>'imglink'));
[/quote]

So his method seems to work pretty well. However how would you incorporate rollovers?

I tried passing the onmouseover and onmouseout as an array as such but with out luck:
Code:
<?= anchor('/thoughts/more/'.$row->id,img(
array('src'=>'img/thoughts/readmore_a.jpg',
      'border'=>'0','alt'=>'Read More'),
array('onmouseover'=> 'readMore.src='base_url().'img/thoughts/readmore_b.jpg";',
      'onmouseout'=>'readMore.src='base_url().'img/thoughts/readmore_a.jpg";',
      'id' =>'readmore')));?>

Any ideas?
#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.
#13

[eluser]elaniobro[/eluser]
The output is correct, and displays the correct code. However it does not appear to be printing to the screen, i.e. the image is not being displayed, nor is the space it would take up.
#14

[eluser]Eason[/eluser]
[quote author="elaniobro" date="1268213075"]The output is correct, and displays the correct code. However it does not appear to be printing to the screen, i.e. the image is not being displayed, nor is the space it would take up.[/quote]

What's the output HTML?
#15

[eluser]elaniobro[/eluser]
Apparently it does work, I just didn't have the correct path like you had said.(img is diffrent then what I posted) However another issue did arise, where or how do you put the array('id'=>'myID') in your anchor_url()?

so in essense how would I make your anchor_url():
Code:
&lt;?= anchor_img('/resume/download', array(), 'img/resume/resume_dl.gif', array('border'=>'0', 'alt' => 'testing image')) ?&gt;

include all of the information seen here using the img() inside of the anchor()?
Code:
&lt;?= anchor('/resume/download',img(array('src'=>'img/resume/resume_dl.gif','border'=>'0','alt'=>'Download Resume','height'=>'46','width'=>'51')),array('id'=>'resume-dl')); ?&gt;
#16

[eluser]mohsin917[/eluser]
Hello.. I'm using this to attach image with anchor.. Its working
Code:
anchor('cheater_management/view_cheaters/'.$row->cID,
    "<img >config->item('includes')."/images/enable.png' width='14' border=0 />");

But the thing I'm not understanding is this good or bad approach. :question:

If bad than always have to make an anchor_image or other function to add image ??
#17

[eluser]elaniobro[/eluser]
[quote author="mohsin917" date="1268220204"]Hello.. I'm using this to attach image with anchor.. Its working
Code:
anchor('cheater_management/view_cheaters/'.$row->cID,
    "<img >config->item('includes')."/images/enable.png' width='14' border=0 />");

But the thing I'm not understanding is this good or bad approach. :question:

If bad than always have to make an anchor_image or other function to add image ??[/quote]

Well, I am no expert, but it seems like it is not efficent. and you should probably re-write your code to as follows:

Code:
&lt;?=anchor('cheater_management/view_cheaters/'.$row->cID,
    img(array('src'=>'/images/enable.png', 'width'=>'14', 'border'=>'0'))?&gt;
#18

[eluser]mohsin917[/eluser]
Well thanx elaniobro, i did not notice the img function..
#19

[eluser]elaniobro[/eluser]
It's all about the blind leading the blind Smile

Now if you can figure out how to do image rollovers let me know!
#20

[eluser]mohsin917[/eluser]
well you advised to use img function in anchor... So is it not having the image rollovers??




Theme © iAndrew 2016 - Forum software by © MyBB