# Get host in backend controller.

**URL:** <https://forum.shopware.com/t/get-host-in-backend-controller/46531>\
**Category:** International (English Only)\
**Tags:** programming\
**Created:** [26. Juni 2017 um 11:38 UTC](https://forum.shopware.com/t/get-host-in-backend-controller/46531 "2017-06-26T11:38:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdnapo](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@mdnapo](https://forum.shopware.com/u/mdnapo)\
**Post date:** [26. Juni 2017 um 11:38 UTC](https://forum.shopware.com/t/get-host-in-backend-controller/46531/1 "2017-06-26T11:38:16Z")

</div>

How do I get the host of the webshop in a backend controller? I thought Shopware()-\>Shop()-\>getHost() would do the trick and it does when I’m using a frontend controller, but when using this in a backend controller the shop returned from Shopware()-\>Shop() is always null. Can anyone tell me what causes this behaviour? Thnx in advance!

---

<div class="post-metadata">

**Author:** ![DanielNogel](https://avatars.discourse-cdn.com/v4/letter/d/96bed5/32.png) [@DanielNogel](https://forum.shopware.com/u/DanielNogel)\
**Post date:** [26. Juni 2017 um 12:39 UTC](https://forum.shopware.com/t/get-host-in-backend-controller/46531/2 "2017-06-26T12:39:08Z")

</div>

Hi,

the Backend does not have a Shop object, as it doesn’t “know”, which of your multishops to use. But you can create a ShopContext object easily:

```
        /** @var \Shopware\Bundle\StoreFrontBundle\Service\ContextServiceInterface $contextService */
        $contextService = $this->get('shopware_storefront.context_service');
        $host = $contextService->createShopContext(1)->getShop()->getHost();

```

You just need to replace the “1” with the shop ID you want to have.

&nbsp;

Best regards,

Daniel

---

<div class="post-metadata">

**Author:** ![mdnapo](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@mdnapo](https://forum.shopware.com/u/mdnapo)\
**Post date:** [26. Juni 2017 um 14:11 UTC](https://forum.shopware.com/t/get-host-in-backend-controller/46531/3 "2017-06-26T14:11:24Z")

</div>

Hi Daniël,

Thank you for the quick response. I got it to work by using the following function in my controller to access the Shop object.&nbsp;

```
 private function getShop() { $em = $this-\>get('models'); $repo = $em-\>getRepository(Shopware\Models\Shop\Shop::class); $shop = $repo-\>findById(1); return $shop[0]; }

```

Is there a significant downside to this method compared to the example you posted?

Best regards,

Donné
