# Plugin eingene Components einbinden

**URL:** https://forum.shopware.com/t/plugin-eingene-components-einbinden/19785
**Category:** Shopware 3.5
**Tags:** programming
**Created:** [16. April 2014 um 12:24 UTC](https://forum.shopware.com/t/plugin-eingene-components-einbinden/19785 "2014-04-16T12:24:02Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![hbee](https://avatars.discourse-cdn.com/v4/letter/h/f08c70/32.png) [@hbee](https://forum.shopware.com/u/hbee)
#### Post date: [16. April 2014 um 12:24 UTC](https://forum.shopware.com/t/plugin-eingene-components-einbinden/19785/1 "2014-04-16T12:24:02Z")

</div>

hi, ich kann in einem Plugin ja eigene klassen als Components einbinden: ` public function install() { $this-\>subscribeEvent( 'Enlight\_Bootstrap\_InitResource\_Mycomponent', 'onInitMyComponent' ); } public function onInitMyComponent(Enlight\_Event\_EventArgs $args) { $this-\>Application()-\>Loader()-\>registerNamespace( 'Shopware\_Components', $this-\>Path() . 'Components/' ); $component = new Shopware\_Components\_Mycomponent(); return $component; } ` Das funktioniert mit einer Klasse auch wunderbar. Wie kann ich aber eine ganze Library die ich im Components-Ordner habe einbinden? Ich habe versucht einen eigenen auto-loader einzubinden: ` public function init() { spl\_autoload\_register(array($this,'\_\_loader')); } private function \_\_loader ($className) { $className = str\_replace('\\','/',$className); require\_once(\_\_DIR\_\_ . '/Components/' . $className . '.php'); } ` Das funktioniert soweit auch. aber an manchen stellen bekomme ich dann einen Fehler dass Dateien im Components-Verzeichnis nciht gefunden werden können. Sind ja auch nicht da: [quote] Fatal error: require\_once() [function.require]: Failed opening required ‚/shopware42/engine/Shopware/Plugins/Community/Frontend/MyPlugin/Components/shopware/models/media/c2fml.php‘ (include\_path=’/shopware42/engine/Library/:/shopware42/templates/’) in /shopware42/engine/Shopware/Plugins/Community/Frontend/MyPlugin/Bootstrap.php on line 44 [/quote] Wie wäre hier das generelle Vorgehen wenn man eigene PHP-Libraries einbinden möchte? Vielen Dank

---

<div class="post-metadata">

### Author: ![hbee](https://avatars.discourse-cdn.com/v4/letter/h/f08c70/32.png) [@hbee](https://forum.shopware.com/u/hbee)
#### Post date: [17. April 2014 um 20:49 UTC](https://forum.shopware.com/t/plugin-eingene-components-einbinden/19785/2 "2014-04-17T20:49:33Z")

</div>

Niemand? Macht das keiner? Gesendet von meinem iPhone mit Tapatalk

---

<div class="post-metadata">

### Author: ![Thomas](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/thomas/32/8167_2.png) [@Thomas](https://forum.shopware.com/u/Thomas)
#### Post date: [18. April 2014 um 09:41 UTC](https://forum.shopware.com/t/plugin-eingene-components-einbinden/19785/3 "2014-04-18T09:41:44Z")

</div>

Eventuell helfen dir die beiden Links weiter: [programmierung-f56/shopware-4-2-weitere-pfade-im-autoloader-registrieren-t19406.html](http://forum.shopware.de/programmierung-f56/shopware-4-2-weitere-pfade-im-autoloader-registrieren-t19406.html) [http://www.thomas-eiling.de/verwendung- … lugins/302](http://www.thomas-eiling.de/verwendung-eines-eigenen-autoloader-innerhalb-eines-shopware-plugins/302) Gruß

---

<div class="post-metadata">

### Author: ![hbee](https://avatars.discourse-cdn.com/v4/letter/h/f08c70/32.png) [@hbee](https://forum.shopware.com/u/hbee)
#### Post date: [21. April 2014 um 13:44 UTC](https://forum.shopware.com/t/plugin-eingene-components-einbinden/19785/4 "2014-04-21T13:44:01Z")

</div>

[quote=“tonne”]Eventuell helfen dir die beiden Links weiter: [programmierung-f56/shopware-4-2-weitere-pfade-im-autoloader-registrieren-t19406.html](http://forum.shopware.de/programmierung-f56/shopware-4-2-weitere-pfade-im-autoloader-registrieren-t19406.html) [http://www.thomas-eiling.de/verwendung- … lugins/302](http://www.thomas-eiling.de/verwendung-eines-eigenen-autoloader-innerhalb-eines-shopware-plugins/302) Gruß[/quote] hi, danke diese beiden Links hatte ich schon gefunden. Der erste hilft mir nicht weiter. Das klappt bei mir gar nnicht: ` $this-\>Application()-\>Loader()-\>registerNamespace('MyLibrary', \_\_DIR\_\_ . '/Components/MyLibrary/API/', '\\'); $client = new MyLibrary\Client($this-\>\_user, $this-\>\_token); ` [quote]Fatal error: Class ‘MyLibrary\API\Client’ not found[/quote] Die Methode von Thomas Eiling habe ich ja im Prinzip so umgesetzt. Leider sucht er dann auch andere Klassen in meinem Components-Verzeichnis. Zumindest wenn der Cache gellert ist und mein Controller direkt aufgerufen wird.

---

<div class="post-metadata">

### Author: ![Thomas](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/thomas/32/8167_2.png) [@Thomas](https://forum.shopware.com/u/Thomas)
#### Post date: [21. April 2014 um 13:54 UTC](https://forum.shopware.com/t/plugin-eingene-components-einbinden/19785/5 "2014-04-21T13:54:28Z")

</div>

[quote=„hbee“]Die Methode von Thomas Eiling habe ich ja im Prinzip so umgesetzt. Leider sucht er dann auch andere Klassen in meinem Components-Verzeichnis. Zumindest wenn der Cache gellert ist und mein Controller direkt aufgerufen wird.[/quote] Mach doch um das require\_once noch ein file\_exists. So in etwa: ` $className = str\_replace('\\','/',$className); $fileName = \_\_DIR\_\_ . '/Components/' . $className . '.php'; if(file\_exists($fileName)){ require\_once($fileName); } ` Dann sollte es doch funktionieren oder? Gruß

---

<div class="post-metadata">

### Author: ![hbee](https://avatars.discourse-cdn.com/v4/letter/h/f08c70/32.png) [@hbee](https://forum.shopware.com/u/hbee)
#### Post date: [21. April 2014 um 14:11 UTC](https://forum.shopware.com/t/plugin-eingene-components-einbinden/19785/6 "2014-04-21T14:11:11Z")

</div>

[quote] Mach doch um das require\_once noch ein file\_exists. [/quote] ja, auch eine Idee. Vielen Dank.
