# Html helper img src and class

**URL:** <https://discourse.cakephp.org/t/html-helper-img-src-and-class/1274>\
**Category:** Need Help\
**Created:** [October 3, 2016, 1:45am UTC](https://discourse.cakephp.org/t/html-helper-img-src-and-class/1274 "2016-10-03T01:45:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [October 3, 2016, 1:45am UTC](https://discourse.cakephp.org/t/html-helper-img-src-and-class/1274/1 "2016-10-03T01:45:01Z")

</div>

Ok original code in listview prior to helper:

```auto
$linev = '';
 $elink = DIR . "dog/view?dogid={$row->dogid}";
 $linev = "<td class=\"imgtd\"><a href=" . $elink . ">";
 $linev = $linev . '<img src="' . "../webroot/" . 'upload/imgdogs/' . $row->dogpic . '" alt="" class="image"></a></td>';
 echo $linev;

```

This opens a view / detailed page and works. the url looks like

```auto
http://localhost/cakephp/dog/view?dogid=91

```

Now the code I attempted, docs didn’t show a complete example of an image with link with class applied

```auto
                    echo '<td>';
                    echo $this->Html->link(
                            $this->Html->image('imgdogs/' . $row->dogpic, array(
                                'class' => 'image',
                                'alt' => ''
                            )), array(
                        'controller' => 'Dogs',
                        'action' => 'view', '?dogid=' . $row->dogid
                            ), array(
                        'class' => 'imgtd',
                        'escape' => false //to allow the image tag within the link
                            )
                    );
                    echo '</td>';

```

which works, but the view page has this for url

```auto
http://localhost/cakephp/dogs/view/%3Fdogid%3D91

```

A slash to right of view and %3F and %3D. How do I use helper yet have this

```auto
http://localhost/cakephp/dog/view?dogid=91

```

I am fairly new to cakephp, but not php. I have also used laravel in past.

Note, found example on stackoverflow.

---

<div class="post-metadata">

**Author:** ![Graziel](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Graziel](https://discourse.cakephp.org/u/Graziel)\
**Post date:** [October 3, 2016, 2:29am UTC](https://discourse.cakephp.org/t/html-helper-img-src-and-class/1274/2 "2016-10-03T02:29:26Z")

</div>

[http://book.cakephp.org/3.0/en/views/helpers/html.html#creating-links](http://book.cakephp.org/3.0/en/views/helpers/html.html#creating-links)

```
echo $this->Html->link('View image', [
    'controller' => 'Images',
    'action' => 'view',     
    1,
    '?' => ['height' => 400, 'width' => 500]
]);
```

---

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [October 3, 2016, 3:20am UTC](https://discourse.cakephp.org/t/html-helper-img-src-and-class/1274/3 "2016-10-03T03:20:54Z")

</div>

Ok thanks, I saw it it docs, but it didn’t catch me. this line did the trick

```auto
'?' => ['height' => 400, 'width' => 500]

```

Just changed to

```auto
'?' => ['dogid' => $row->dogid]

```

A followup, I have the images in

```auto
mysite/webroot/img/imgdogs

```

any idea how to call them if folder was

```auto
mysite/webroot/upload/imgdogs

```

---

<div class="post-metadata">

**Author:** ![Graziel](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Graziel](https://discourse.cakephp.org/u/Graziel)\
**Post date:** [October 3, 2016, 5:05am UTC](https://discourse.cakephp.org/t/html-helper-img-src-and-class/1274/4 "2016-10-03T05:05:27Z")

</div>

in `app.php` there is [https://github.com/cakephp/app/blob/master/config/app.default.php#L49](https://github.com/cakephp/app/blob/master/config/app.default.php#L49)  
`'imageBaseUrl' => 'img/',` just modify it to your needs

> [@jimgwhit](#):
>
> Ok thanks, I saw it it docs, but it didn’t catch me.

yeah sometimes things are mentioned only once in docs so it can be hard to catch
