# DemoDataController - "DemoDataController does not exist in"

**URL:** https://forum.shopware.com/t/demodatacontroller-demodatacontroller-does-not-exist-in/67042
**Category:** Programming (EN)
**Created:** [19. Mai 2020 um 08:48 UTC](https://forum.shopware.com/t/demodatacontroller-demodatacontroller-does-not-exist-in/67042 "2020-05-19T08:48:17Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![alphabetus](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@alphabetus](https://forum.shopware.com/u/alphabetus)
#### Post date: [19. Mai 2020 um 08:48 UTC](https://forum.shopware.com/t/demodatacontroller-demodatacontroller-does-not-exist-in/67042/1 "2020-05-19T08:48:17Z")

</div>

Hello.  
I was following the video:&nbsp;[https://academy.shopware.com/courses/take/shopware-6-developer-training-english/lessons/9225170-data-storefront](https://academy.shopware.com/courses/take/shopware-6-developer-training-english/lessons/9225170-data-storefront)  
When I try to access the website the following error appears:

> "
> 
> {„errors“:[{„code“:„0“,„status“:„500“,„title“:„Internal Server Error“,„detail“:„Class \DemoDataController does not exist in /Users/alphabetus/Documents/repos/shopware01/custom/plugins/SwagShopFinder/src/Core/Api/DemoDataController.php (which is being imported from \u0022/Users/alphabetus/Documents/repos/shopware01/custom/plugins/SwagShopFinder/src/Resources/config/routes.xml\u0022). Make sure annotations are installed and enabled.“}]}

I’m stuck for a while trying to understand what is wrong.  
The video never shows the full code that the guy is using only references.  
Probably some imports are missing

DemoDataController.php goes as follows:  
&nbsp;

```
countryRepository = $countryRepository;
    $this->shopFinderRepository = $shopFinderRepository;
  }

    /**
     * @Route("/api/v{version}/_action/swag-shop-finder/generate", name="api.custom.swag_shop_finder.generate", methods={"POST"})
     * @param Context $context
     * @return Response
     * @throws CountryNotFoundException
     * @throws InconsistentCriteriaIdsException
     */
  public function generate(Context $context): Response
  {
    $faker = Factory::create();
    $country = $this->getActiveCountry($context);

    $data = [];
    for($i = 0; $i < 50; $i++){
      $data[] = [
        'id' => Uuid::randomHex(),
        'active' => true,
        'name' => $faker->name,
        'street' => $faker->streetAddress,
        'postcode' => $faker->postcode,
        'city' => $faker->city,
        'countryId' => $country->getId()
      ];
    }

    $this->shopFinderRepository->create($data, $context);
    return new Response('', Response::HTTP_NO_CONTENT);
  }

  /**
  * @param Context $context
  * @return CountryEntity
  * @throws CountryNotFoundException
  * @throws InconsistentCriteriaIdsException;
  **/
  private function getActiveCountry(Context $context): CountryEntity
  {
    $criteria = new Criteria();
    $criteria->addFilter(new EqualsFilter('active', '1'));
    $criteria->setLimit(1);

    $country = $this->countryRepository->search($criteria, $context)->getEntities()->first();
    if ($country === null) {
      throw new CountryNotFoundException('');
    }

    return $country;
  }
}

```

&nbsp;

---

<div class="post-metadata">

### Author: ![Rahmspinat](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@Rahmspinat](https://forum.shopware.com/u/Rahmspinat)
#### Post date: [16. Juni 2020 um 18:31 UTC](https://forum.shopware.com/t/demodatacontroller-demodatacontroller-does-not-exist-in/67042/2 "2020-06-16T18:31:18Z")

</div>

Hello,

you use the wrong imports.

Here is my working DemoDataController

&nbsp;

```
countryRepository = $countryRepository;
    $this->shopFinderRepository = $shopFinderRepository;
  }

  /**
   * @Route("/api/v{version}/_action/swag-shop-finder/generate", name="api.custom.swag_shop_finder.generate", methods={"POST"})
   * return Response
   */
  public function generate(Context $context): Response {
    $faker = Factory::create();
    $country = $this->getActiveCountry($context);

    $data = [];
    for ($i = 0; $i < 50; $i++) {
      $data[] = [
        'id' => Uuid::randomHex(),
        'active' => true,
        'name' => $faker->name,
        'street' => $faker->streetAddress,
        'postCode' => $faker->postcode,
        'city' => $faker->city,
        'countryId' => $country->getId(),
      ];
    }
    $this->shopFinderRepository->create($data, $context);

    return new Response('', Response::HTTP_NO_CONTENT);
  }

   /**
   * @param Context $context
   * @return CountryEntity
   * @throws CountryNotFoundException
   * @throws InconsistentCriteriaIdsException
   */
  private function getActiveCountry(Context $context): CountryEntity {
    $criteria = new Criteria();
    $criteria->addFilter(new EqualsFilter('active', '1'));
    $criteria->setLimit(1);

    $country = $this->countryRepository->search($criteria, $context)->getEntities()->first();
    if($country === null) {
      throw new CountryNotFoundException('');
    }
    return $country;
  }

}

```

&nbsp;

---

<div class="post-metadata">

### Author: ![komoito](https://avatars.discourse-cdn.com/v4/letter/k/48db29/32.png) [@komoito](https://forum.shopware.com/u/komoito)
#### Post date: [14. Juli 2020 um 08:34 UTC](https://forum.shopware.com/t/demodatacontroller-demodatacontroller-does-not-exist-in/67042/3 "2020-07-14T08:34:13Z")

</div>

Hi for me helped adding the namespace to my controller. Obviously on training course there is no namespace, and it doesn’t work. Also i had to add created\_ad and updated\_at to my migration code.

---

<div class="post-metadata">

### Author: ![pramilamanandhar](https://avatars.discourse-cdn.com/v4/letter/p/e274bd/32.png) [@pramilamanandhar](https://forum.shopware.com/u/pramilamanandhar)
#### Post date: [20. Mai 2021 um 11:07 UTC](https://forum.shopware.com/t/demodatacontroller-demodatacontroller-does-not-exist-in/67042/4 "2021-05-20T11:07:05Z")

</div>

my DemoDataController code is  
\<?php declare(strict\_types=1);

```
use Faker\Factory;

use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\System\Country\CountryEntity;
use Shopware\Core\System\Country\Exception\CountryNotFoundException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;

/**
 * @RouteScope(scopes={"api"})
 */

class DemoDataController extends AbstractController
{
    /**
     * @var EntityRepositoryInterface
     */
    private $countryRepository;

    /**
     * @var EntityRepositoryInterface
     */
    private $shopFinderRepository;

    public function __construct(
        EntityRepositoryInterface $countryRepository, EntityRepositoryInterface $shopFinderRepository){
        $this->countryRepository = $countryRepository;
        $this->shopFinderRepository = $shopFinderRepository;
    }

    /**
     * @Route("/api/v{version}/_action/swag-shop-finder/generate", name="api.custom.swag_shop_finder.generate", methods={"POST"})
     * @param Context $context
     * @return Response
     */
    public function generate(Context $context): Response
    {
        $faker = Factory::create();
        $country = $this->getActiveCountry($context);
        $data = [];
        for($i=0; $i<=25; $i++){
            $data[] = [
                'id' => Uuid::randomHex(),
                'name' => $faker->name,
                'countryId' => $country->getId(),
                'active' => true,
                'postal_code' => $faker->postcode,
            ];
        }

        $this->shopFinderRepository->create($data, $context);
        return new Response("", Response::HTTP_NO_CONTENT);
    }

    /**
     * @param Context $context
     * @return CountryEntity
     * @throws CountryNotFoundException
     * @throws InconsistentCriteriaIdsException
     */
    private function getActiveCountry(Context $context): CountryEntity
    {
        $criteria = New Criteria();
        $criteria->addFilter(new EqualsFilter('active', '1'));
        $criteria->setLimit(1);

        $result = $this->countryRepository->search($criteria, $context)->getEntities->first();

        if($result===null){
            throw new CountryNotFoundException();
        }
        return $result;

    }

}

I got error 
{
  "errors": [
    {
      "code": "0",
      "status": "500",
      "title": "Internal Server Error",
      "detail": "The controller for URI \"/api/v2/_action/swag-shop-finder/generate\" is not callable: Controller \"DemoDataController\" does neither exist as service nor as class."
    }
  ]
}

```

can you help??@rahmspinat

---

<div class="post-metadata">

### Author: ![smeuser](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/smeuser/32/14488_2.png) [@smeuser](https://forum.shopware.com/u/smeuser)
#### Post date: [11. August 2021 um 07:56 UTC](https://forum.shopware.com/t/demodatacontroller-demodatacontroller-does-not-exist-in/67042/5 "2021-08-11T07:56:44Z")

</div>

I had the same problem and i solved it by checking my ide (using phpstorm).  
In my case there were some imports missing. In the very first i forgot the namespace definition in my DemoDataController.php and this did lead to the exact same error (DemoDataController class is missing).  
Later on i had to add some use statements in addition and phpstorm helped me with this quite comfortable.
