how can i write helper link with image link in span tag cakephp

343 Views Asked by At

i want to generate this

<a href="/users/signup" class="sf-with-ul">
                                <span class="profile-avatar">
                                    <img alt="" src="img/avatar/anonymous.png" height="40" width="40">
                                </span>
                    </a>

I have written

 <?php echo $this->Html->link(
                        $this->Html->image('avatar/anonymous.png',array('height' =>40,'width'=>'40')), array('controller' => 'users', 'action' => 'signup'),
                        array('class' => 'sf-with-ul', 'escape' => false));?>

which generates

<a href="/users/signup" class="sf-with-ul"><span class="profile-name"></span><img src="/FindTutor/img/avatar/anonymous.png" height="40" width="40" alt="" /></a> 

Any help? Thanks in advance.

2

There are 2 best solutions below

0
On

Try this:

   <?php 

    $img    =   $this->Html->image("avatar/anonymous.png", 
        array("height" => "40", "width" => "40")
    );

    $img_span   =   $this->Html->tag('span', $img, 
        array('class' => 'profile-avatar')
    );

    echo $this->Html->link($img_span, 
        array("controller" => "users", "action" => "signup"),
        array("escape" => false)
    );
?>          

This looks a little lengthy but it's easier to understand and works exactly like what you're asking for.

Peace! xD

0
On

you can try this just change your image path

<?php echo $this->Html->link('<span class="profile-avatar">'. $this->Html->image('home/logo.png',array('width'=>'40px','height'=>'40px'), array('alt' => '')), array('controller' => 'users', 'action' => 'signup' ), array('class' => 'sf-with-ul', 'escape' => false)).'</span>';?>