Welcome Guest, Not a member yet? Register   Sign In
Image in anchor
#1

[eluser]rijobo[/eluser]
I've found a function that I can put in my url_helper, which i can use to put images in my anchor. But when I use this function, it does nothing.

This is what I use:

Controller:

Code:
function index()
    {
        $this->load->helper('url_helper');
        $this->load->view('administrator_view');
    }

View:

Code:
<?php anchor_img('producttoevoegen', 'title="Nieuw product toevoegen"', '../assets/images/producttoevoegen.jpg', 'alt="Nieuw product toevoegen"'); ?>

Function in helper:

Code:
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>';
}
#2

[eluser]cahva[/eluser]
You might want to actually print the damn thing Smile So..
Code:
&lt;?php echo anchor_img('...
#3

[eluser]JoostV[/eluser]
You can also use the normal URL helper

Code:
$img = img(array('src' => base_url() . 'assets/images/producttoevoegen.jpg', 'class' => 'icon', 'alt' => 'Toevoegen'));
echo anchor($page, $img, array('title' => 'Nieuw product toevoegen'));

If you need to reuse the code, create your own helper function. Place it in a custom helper in your /helper directory
Code:
/**
* Return an add button that links to a certain URL
* @param string $url The location for the url
* return string the HTML href string
*/
function addbutton($url){
    $img = img(array('src' => base_url() . 'assets/images/producttoevoegen.jpg', 'class' => 'icon', 'alt' => 'Toevoegen'));
    return anchor($page, $img, array('title' => 'Nieuw product toevoegen'));
}




Theme © iAndrew 2016 - Forum software by © MyBB