I'm building an ecommerce platform that takes the very first part of the URL and decides what to do with it based on a database query.
What's the best way to do this, in terms of how to call other controllers?
Should each controller be a controller, or would it be appropriate to just use normal classes and call them instead (if I weren't to use modules)?
At the moment, I've got:
if (we have a product with this url)
return Controller_Product::action_index();
But that seems a little disjointed as it's not really a controller.
If I create just a normal class called Product, if I wanted to call Product::product() it only seems to work if I have a __construct() function - why is that?
My front controller is a controller uses the Theme class to create the page template. The different sections of the template (like sidebar, body, etc) are fetched using HMVC calls to module controllers.
This way you completely decouple the two, and for the module controller it just looks like a standard request, so you can code it like you would any other controller action.
It is (imho) not a good idea to call classes directly, especially cross namespace, as that would tightly couple the two, and makes changes very complex.
As to your issue, you have a method called product()? And it is defined statically? You have to be careful for the PHP4 compliance fallback, where a method with the same name as the class acts like a constructor in absence of __construct.