Welcome Guest, Not a member yet? Register   Sign In
same old anchor image help wanted
#1

[eluser]DumpProgrammer[/eluser]
I am having troubles anchoring an image using the codeigniter url helper. I had come accross a thread on the forum that had an example on how to add an image to the anchor including the base_url function but I did not copy thinking I could find it again.

Is there a way I can use an image anchor without having to use the anchor_img() function?
#2

[eluser]helmutbjorg[/eluser]
Code:
echo anchor('http://www.google.com', img('images/photo.gif'));
#3

[eluser]DumpProgrammer[/eluser]
I have tried it but I am getting an error [client 127.0.0.1] PHP Fatal error: Call to undefined function img(). This is the code I have done
Code:
echo anchor('blog/post/'.$feature['id'],img(base_url().'/uploads/shout1.png'));
#4

[eluser]helmutbjorg[/eluser]
Load the html helper...

Code:
$this->load->helper('html');

You can set this to load automatically in your autoload.php config file.
#5

[eluser]helmutbjorg[/eluser]
Also you do not need to specify the base_url() with this function. It does it for you. That's why it is called a 'helper'. Just like the anchor function.
#6

[eluser]CroNiX[/eluser]
Just add straight html into the code:
Code:
echo anchor('blog/post/'.$feature['id'],'<img src="&lt;?php echo base_url().'/uploads/shout1.png" />');

or create an img php helper so you can use the original posted code.
Code:
function img($url)
{
    return '<img src="' . $url . '" />';
    //or use base url here so you don't have to enter it each time so you can just pass 'uploads/shout1.png' and it will add the base url auto
    // return '<img src="' . base_url() . $url . '" />';
}
#7

[eluser]DumpProgrammer[/eluser]
Thanks after loading the html helper that solved the problem. Will I be able to load the class, title and stuff as an array?
#8

[eluser]helmutbjorg[/eluser]
Functions work like normal and will accept an array. CMON JUST TRY IT! Get your hands dirty and actually take a look at the functions you are calling!!!
#9

[eluser]DumpProgrammer[/eluser]
Thanx for the nudge, I have use this method instead I dont know if its the best solution

Code:
$image_properties = array(
          'src' => 'images/picture.jpg',
          'alt' => 'Me, demonstrating how to eat 4 slices of pizza at one time',
          'class' => 'post_images',
          'width' => '200',
          'height' => '200',
          'title' => 'That was quite a night',
          'rel' => 'lightbox',
);

img($image_properties);
#10

[eluser]helmutbjorg[/eluser]
Looks good buddy!




Theme © iAndrew 2016 - Forum software by © MyBB