I am soon embarking on a project of epic proportions and are going to use OOP for the first time in MODX Revolution. I have two questions: What is the best practice for including the class-files? Can I use the magic method __autoload() to do this and where in Revolution should I put this?
...I believed it was Friday...
Hi,
I tend to use a wrapper class via simple manual inclusion in a Snippet, which calls XPDO->addPackage('MyPackage') in the _construct(), and also contains directly related helper methods, or further inclusions for other shared utility classes...
Peeps are encouraged to keep their own packages in core/components (aids distribution/upgrades), but the framework itself doesn't actually enforce this (space for someone to correct me here...).
With this in mind, I keep a few related packages within a main namespacing folder because I like to know where everything is in case of emergency, and also because the Packages themselves are so application specific that they don't need to be individually installed, or publicly distributed.
For example,
core/components
-------------- /mycompany/
----------------- /library/
--------------------- sharedhelper.class.php
----------------- /mypackage1/
---------------------- /build/
---------------------- /controllers/
---------------------- /helpers/
---------------------- /model/
-------------------------- /schema/
-------------------------------- package1.schema.xml
-------------------------- package1.class.php
---------------------- /util/
------------------------- package1helper.class.php
----------------- /mypackage2/
---------------------- /build/
---------------------- /controllers/
---------------------- /helpers/
---------------------- /model/
-------------------------- /schema/
-------------------------------- package2.schema.xml
-------------------------- package2.class.php
---------------------- /util/
------------------------- package2helper.class.php
Sorry about the formatting.
package[1,2].class.php are the wrapper classes for all my Xpdo queries and business logic in this example, and sharedhelper.class.php gets used by both packages.
[ed. note: thenewmanifesto last edited this post 14 years, 11 months ago.]
Im sorry for not understanding your reply so I try to ask my question in another way:
In Evolution I would put my class-files in a folder inside assets/snippets/myclassfiles/
Then I would make a snippet and place it in the top of the template that loaded my class files with __autoload().
How can I do something like this in the best way in Revolution?
...I believed it was Friday...
Hi Thorjarle,
core/components/foo/
Then in a snippet:
include_once('core/components/foo/bar.php');