Good time of day!
Likely, to say that I am not writing my CMS, I just want to clarify that this is Explay. In this regard, I will write about what has already been implemented and is available in the
source code .
In this article we will discuss the "responses" of the modules (unfortunately, I could not come up with a more clever name). Roughly speaking, by answer, I mean
return $ var of a certain method or function. Here it is necessary to make a reservation that the
MVC design
pattern is used , where the module is, of course, a model. Further, some common words from how MVC works in my CMS.
')
The task of the main controller is to call the module method (the modules are represented by classes) and return its response to the view. The presentation is not immediately a templating agent, but an intermediate “controller” that already communicates with the templating engine. In the approximate drawing:

Now the main thing - the responses of the modules. In my CMS, the module response should always be an object of class ModuleResponse. An object of this class stores any other objects that the template engine will process. Thanks to this method, we get rid of the need to write code for processing templates in modules, thereby removing the binding of modules to a specific template engine and, moreover, we can use several template engines simultaneously. This way it’s easy to switch from XSLT to Smarty or anything else.
Especially important for me is that for generating a template (which goes directly to the HTML code of the page) and generating an XML response for AJAX, you can use one PHP code.
When using the above method in the module code, we obtain:
$oResponse = new ModuleResponse;
$oResponse->setTemplate ('blogs/post'); //
$oResponse->addObject ($object);
return $oResponse;
It is understood that the interface of the object “put” in the response of the module allows you to get all of its properties or build XML. In the case of XML in my CMS, all objects that fall into the ModuleResponse should have the __toXML () method, which allows you to enter new classes of objects on the go.