Ich habe versucht mit namespaces zu arbeiten weil ich verstehen wollte wie ich die Core Functionalität anpassen kan. Ich hatte gedacht meine eigene Erweiterung zu erstellen innerhalb sein eigene Namespace. Alles aus diese Namespace wurde die geänderten Klassen verwenden ohne das restlige von Contao zu ändern.
Um dies zu testen habe ich eine kurze Erweiterung geschrieben, die ich unten hinzugefügt habe. Das Ergebnis ist nicht wie erwartet, das ganse Contao verwendet jetzt meine Änderungen an der Controller Klasse, auch die Module im Contao-Namespace. Vielleicht ist es genau so wie es funktionieren soll, aber so weit ich verstehe muss der Code nur in sein eigenen Namespace gucken (wenn nicht angegeben, wo er sonst gucken soll. http://php.net/manual/en/language.namespaces.basics.php).
Kann jemand sich meinem Code anschauen und mir sagen, was ich falsch gemacht habe?
I have been trying to get the namespaces to work in order to understand how I can alter core functionality. I had thought I would create my extension within its own namespace. Everything within that namespace would use the altered classes, leaving the rest of Contao unaltered (using the original core classes).
To test this I wrote a short extension which I included the code of below. The result is not as expected; all Contao code now uses my alterations to the Controller class, even the Modules in the Contao namespace. Perhaps this is exactly the way it is supposed to work, but for as far as I understand namespacing the code is supposed to look only within it's own namespace if not specified where else to look (http://php.net/manual/en/language.namespaces.basics.php).
Can someone look at my code and tell me where I might have gone wrong here?
mymodule/classes/Controller.php
mymodule/config/autoload.iniCode:namespace MyModule; abstract class Controller extends \Contao\Controller { // ... custom changes ... }
mymodule/config/autoload.php
>> both generated
mymodule/config/config.php
mymodule/dca/tl_module.phpCode:$GLOBALS['FE_MOD']['navigationMenu']['navigationroot'] = 'ModuleNavigationRoot';
mymodule/modules/ModuleNavigationRoot.phpCode:$GLOBALS['TL_DCA']['tl_module']['palettes']['navigationroot'] = $GLOBALS['TL_DCA']['tl_module']['palettes']['navigation'];
Code:namespace MyModule; class ModuleNavigationRoot extends \Contao\ModuleNavigation { }
Lesezeichen