I’m starting to write a application in php with one of my friends and was wondering, if you have any advice on how to implement module support into our application.
Or is there a way how to automatically load modules written in php by a php application? Or should i just rely on __autoload function?
And we don’t need plugins that are installable via a web interface, we just need some clever way to associate web pages of our project to some classes (they will render the page) so index.php can call the right class and retrieve it’s generated sub-page.
And we are not using any kind of framework, for now at least.
Re your comment: Autoloading in conjunction with strict file naming would be totally enough in this case IMO.
You could define a specific namespace (not in the new PHP 5.3
namespaceway, just in the sense of a common prefix to names), e.g.Module_*for module class names.You could then organize your modules in directories with class files that contain exactly one class definition, for example:
Your autoloader function would then, whenever a
Module_*class is requested:include the correct file from the right directory.
That’s the way e.g. the Zend Framework does it, and does so pretty well.
Consider choosing a more specific namespace than
Module_to assure interoperability with other scripts and applications if that is an option in the future.Slightly related: In a PHP project, how do you organize and access your helper objects?