# Eigenen Controller von eigenem Controller erweitern lassen

**URL:** <https://forum.shopware.com/t/eigenen-controller-von-eigenem-controller-erweitern-lassen/24542>\
**Category:** Shopware 3.5\
**Tags:** programming\
**Created:** [13. Januar 2015 um 13:32 UTC](https://forum.shopware.com/t/eigenen-controller-von-eigenem-controller-erweitern-lassen/24542 "2015-01-13T13:32:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![moep](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@moep](https://forum.shopware.com/u/moep)\
**Post date:** [13. Januar 2015 um 13:32 UTC](https://forum.shopware.com/t/eigenen-controller-von-eigenem-controller-erweitern-lassen/24542/1 "2015-01-13T13:32:15Z")

</div>

Hallo nochmal! Ich versuche gerade einen generischen Controller zu erstellen, von dem meine spezifischen Controller dann extenden können. Jedoch wird der generische Controller nicht verfügbar gemacht, und ich erhalte eine not found exception. `  
**Fatal error** : Class 'Shopware\_Controllers\_Api\_RestFrontend' not found in **C:\dev\tools\xampp\htdocs\project\engine\Shopware\Plugins\Local\Backend\Project\Controllers\Api\MyProfiles.php** on line **12**  
` In meiner Bootstrap hole ich aber beide Klassen rein. ` $this-\>subscribeEvent( 'Enlight\_Controller\_Dispatcher\_ControllerPath\_Api\_RestFrontend', 'onGetRestFrontendApiController' ); $this-\>subscribeEvent( 'Enlight\_Controller\_Dispatcher\_ControllerPath\_Api\_MyToken', 'onGetMyTokenApiController' ); $this-\>subscribeEvent( 'Enlight\_Controller\_Dispatcher\_ControllerPath\_Api\_MyProfiles', 'onGetMyProfilesApiController' );` ` public function onGetRestFrontendApiController() { return $this-\>Path() . 'Controllers/Api/RestFrontend.php'; } public function onGetMyTokenApiController() { return $this-\>Path() . 'Controllers/Api/MyToken.php'; }` MyProfiles.php `use Shopware\Components\Api\Exception as ApiException; #require\_once('RestFrontend.php'); class Shopware\_Controllers\_Api\_MyProfiles extends Shopware\_Controllers\_Api\_RestFrontend {` RestFrontend.php `use Shopware\Components\Api\Exception as ApiException; class Shopware\_Controllers\_Api\_RestFrontend extends Shopware\_Controllers\_Api\_Rest {` Wenn ich ein require\_once oben reinhaue geht es ohne Probleme. Ich dachte aber, daß ich durch die Event-Registrierung meinen Controller in der gesamten Applikation zur Verfügung gestellt habe – habe ich hier einen Denkfehler? Schöne Grüße, Marc

---

<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:** [13. Januar 2015 um 13:55 UTC](https://forum.shopware.com/t/eigenen-controller-von-eigenem-controller-erweitern-lassen/24542/2 "2015-01-13T13:55:14Z")

</div>

Hi, ja, das Event greift, wenn der ControllerDispatcher nach einem Controller sucht - also wenn ein Request auf einen Controller gelenkt werden soll. Für das extends aber nicht, das passier ja auf ganz anderer Ebene. Da würde ich einfach empfehlen, dass du dir ganz normal deinen Namespace registrierst und da deinen Basis-Controller reinlegst. Die anderen Controller erben dann beispielsweise von Shopware\MyPlugin\Controller\Base.php - das sollte funktionieren. Besten Gruß, Daniel

---

<div class="post-metadata">

**Author:** ![moep](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@moep](https://forum.shopware.com/u/moep)\
**Post date:** [13. Januar 2015 um 15:10 UTC](https://forum.shopware.com/t/eigenen-controller-von-eigenem-controller-erweitern-lassen/24542/3 "2015-01-13T15:10:36Z")

</div>

Hallo Daniel, ich glaube ich habe den Namespace jetzt richtig registriert und kann die Klasse verwenden. Jedoch funktioniert die Extension nicht mehr wie erwartet (also wie zuvor mit der RequireOnce). In meiner Bootstrap.php habe ich ` public function onEnlightControllerFrontStartDispatch(Enlight\_Event\_EventArgs $args) { $this-\>Application()-\>Loader()-\>registerNamespace( 'Shopware\Components', $this-\>Path() . 'Components/' ); $this-\>Application()-\>Loader()-\>registerNamespace( 'Shopware\Controllers\Base', $this-\>Path() . 'Controllers/Base/' ); }` MeinPlugin\Controllers\Base\RestFrontend.php `namespace Shopware\Controllers\Base; use Shopware\Components\Api\Exception as ApiException; class Shopware\_Controllers\_Base\_RestFrontend extends Shopware\_Controllers\_Api\_Rest {` MeinPlugin\Controllers\Api\MyProfiles.php `use Shopware\Controllers\Base\Shopware\_Controllers\_Base\_RestFrontend; use Shopware\Components\Api\Exception as ApiException; class Shopware\_Controllers\_Api\_MyProfiles extends Shopware\_Controllers\_Base\_RestFrontend {` Nun erhalte ich jedoch den Fehler: `  
**Fatal error** : Uncaught exception 'Enlight\_Controller\_Exception' with message 'Action "Api\_Index\_indexAction" not found failure' in C:\dev\tools\xampp\htdocs\project\engine\Library\Enlight\Controller\Action.php:389 Stack trace: #0 C:\dev\tools\xampp\htdocs\project\engine\Library\Enlight\Controller\Action.php(159): Enlight\_Controller\_Action-\>\_\_call('indexAction', Array) #1 C:\dev\tools\xampp\htdocs\project\engine\Library\Enlight\Controller\Action.php(159): Shopware\_Proxies\_ShopwareControllersApiIndexProxy-\>indexAction() #2 C:\dev\tools\xampp\htdocs\project\engine\Library\Enlight\Controller\Dispatcher\Default.php(528): Enlight\_Controller\_Action-\>dispatch('indexAction') #3 C:\dev\tools\xampp\htdocs\project\engine\Library\Enlight\Controller\Front.php(228): Enlight\_Controller\_Dispatcher\_Default-\>dispatch(Object(Enlight\_Controller\_Request\_RequestHttp), Object(Enlight\_Controller\_Response\_ResponseHttp)) #4 C:\dev\tools\xampp\htdocs\project\engine\Shopware\Kernel.php(141): Enlight\_Controller\_Front-\>dispatch() #5 C:\dev\tools\xampp\htdocs\project\vendor\ in **C:\dev\tools\xampp\htdocs\project\engine\Library\Enlight\Controller\Action.php** on line **389**  
` Ist jetzt etwas durch den Namespace kaputt gegangen? Kann ich überhaupt eine API Controller Klasse von meiner eigenen Klasse erweitern? Lg Marc

---

<div class="post-metadata">

**Author:** ![moep](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@moep](https://forum.shopware.com/u/moep)\
**Post date:** [13. Januar 2015 um 15:40 UTC](https://forum.shopware.com/t/eigenen-controller-von-eigenem-controller-erweitern-lassen/24542/4 "2015-01-13T15:40:42Z")

</div>

Ich habe gerade festgestellt, daß ich einfach den Namespace falsch registriert hatte… `$this-\>Application()-\>Loader()-\>registerNamespace( 'Shopware\Controllers\Base', $this-\>Path() . 'Controllers/Base/' );` VS `$this-\>Application()-\>Loader()-\>registerNamespace( 'Shopware\_Controllers\_Base', $this-\>Path() . 'Controllers/Base/' );` Danke für die Unterstützung Daniel! LG Marc
