# Controller Registrierung - Offizieller Kurs "Developer Training Basic"

**URL:** <https://forum.shopware.com/t/controller-registrierung-offizieller-kurs-developer-training-basic/71711>\
**Category:** Installation / Einstieg\
**Created:** [22. Dezember 2020 um 10:42 UTC](https://forum.shopware.com/t/controller-registrierung-offizieller-kurs-developer-training-basic/71711 "2020-12-22T10:42:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juicy](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@Juicy](https://forum.shopware.com/u/Juicy)\
**Post date:** [22. Dezember 2020 um 10:42 UTC](https://forum.shopware.com/t/controller-registrierung-offizieller-kurs-developer-training-basic/71711/1 "2020-12-22T10:42:31Z")

</div>

Hallo, ich lerne gerade mit dem offiziellen Kurs „[Shopware 6 - Developer Training Basic (EN)](https://academy.shopware.com/courses/take/shopware-6-developer-training-english/lessons/9225169-controllers)“ und bin beim Punkt „Controller“ hängen geblieben.

Nach dem ich alles so wie im Kurs nachgebaut habe versuche ich die Url „…/api/v2/\_action/swag-shop-finder/generate“ per POST Request aufzurufen und bekomme die folgende Fehlermeldung:&nbsp; **"The controller for URI „/api/v2/\_action/swag-shop-finder/generate“ is not callable: Controller „DemoDataController“ has required constructor arguments and does not exist in the container. Did you forget to define the controller as a service?"**

Irgendwas muss ich übersehen haben. Gibt es den Quellcode aus dem Kurs irgendwo einzusehen? Kann mir jemand bei dem Fehler sagen was ich vergessen habe?&nbsp;

Hier meine services.xml

Hier mein Controller:&nbsp;

```
declare(strict_types=1);

use Faker\Factory as FakerFactory;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
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 Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
 * @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"})
   *
   * @return Response
   */
  public function generate(Context $context): Response 
  {
    $faker = FakerFactory::create();
    $country = $this->getActiveCountry($context);
    $data = [];
    for ($i = 0; $i < 50; $i++) {
      $data[] = [
        'id' => Uuid::randomHex(),
        'acitve' => 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);
  }

  
  /**
   * getActiveCountry
   *
   * @param Context $context
   * @return CountryEntity
   */
  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:** ![Juicy](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@Juicy](https://forum.shopware.com/u/Juicy)\
**Post date:** [23. Dezember 2020 um 08:14 UTC](https://forum.shopware.com/t/controller-registrierung-offizieller-kurs-developer-training-basic/71711/2 "2020-12-23T08:14:35Z")

</div>

Hier fehlte der Namespace für den Controller. Mein IDE hat dies nicht hevorgehoben. Im Tutorial hat dies aber auch gefehlt.&nbsp;

Falls also jemand eine ähnlihe Fehlemeldung bekommt. Die Datei wrid wohl nicht gefunden. Entweder der Namespace ist falsch oder nicht vorhanden.&nbsp;

---

<div class="post-metadata">

**Author:** ![openmindculture](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/openmindculture/32/8658_2.png) [@openmindculture](https://forum.shopware.com/u/openmindculture)\
**Post date:** [16. Juni 2022 um 15:25 UTC](https://forum.shopware.com/t/controller-registrierung-offizieller-kurs-developer-training-basic/71711/3 "2022-06-16T15:25:35Z")

</div>

Danke @Juicy für den sehr hilfreichen Beitrag!

Für alle verzweifelten, die die Suchmaschine an diese Stelle führt und die sich fragen, wo genau die Namespace-Angabe fehlt (in der DemoDataController.php direkt unter der ersten Zeile, analog zu den bestehenden korrekten Namespace-Angaben in den anderen Plugin-Dateien und wie genau sie lauten muss (was sich auch ohne PHP-Grundwissen aus den anderen Dateien erschließen sollte), hier noch ein hilfreicher Link zu [PHP.net](http://PHP.net) mit Erklärung und Verweis auf PSR-0 und PSR-4: [https://www.php.net/manual/en/language.namespaces.rationale.php](https://www.php.net/manual/en/language.namespaces.rationale.php)

---

<div class="post-metadata">

**Author:** ![openmindculture](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/openmindculture/32/8658_2.png) [@openmindculture](https://forum.shopware.com/u/openmindculture)\
**Post date:** [20. Dezember 2023 um 14:16 UTC](https://forum.shopware.com/t/controller-registrierung-offizieller-kurs-developer-training-basic/71711/4 "2023-12-20T14:16:55Z")

</div>

Da die besagten Videos immer noch unverändert in der Academy online sind und seitdem einige Deprecations stattgefunden haben, habe ich mal einige Informationen gesammelt und in einer subjektiven Auswahl zusammengestellt:

[Shopware 6 changes since the academy training videos:  
https://dev.to/ingosteinke/shopware-changes-since-the-60-dev-training-videos-481o](https://dev.to/ingosteinke/shopware-changes-since-the-60-dev-training-videos-481o)
