Module Answers

    Good time of day!

    Probably, I don’t need to say that I write 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 .

    This article will focus on the “answers” ​​of the modules (unfortunately, I could not come up with a more intelligent name). Roughly speaking, by the answer I mean return $ var of some method or function. Here it is necessary to make a reservation that the MVC design pattern is used , where the module is, of course, the model. Below are some general words on how MVC works in my CMS.

    The task of the main controller is to call the module method (modules are represented by classes) and return its response to the view. The presentation is not performed immediately by the template engine, but by an intermediate “controller”, which already communicates with the template engine. In an example drawing:

    image

    Now about the main thing - the answers of the modules. In my CMS, the module response should always be an object of the ModuleResponse class. 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 template processing code in modules, thereby removing the binding of modules to a specific template engine and, moreover, we get the opportunity to use several template engines at the same time. Thus, it will not be difficult to switch from XSLT to Smarty or something else.

    Particularly important among the advantages for me is that you can use one PHP code to generate a template (which will go directly to the HTML code of the page) and generate an XML response for AJAX.

    Using the above method in the module code, we get: It is understood that the interface of the object "laid" in the module response allows you to get all its properties or build XML. In the case of XML in my CMS, all objects that fall into ModuleResponse must have the __toXML () method, which allows you to introduce new classes of objects on the go.

    $oResponse = new ModuleResponse;
    $oResponse->setTemplate ('blogs/post'); // шаблонизатор на свой вкус может выбрать расширение файла шаблона
    $oResponse->addObject ($object);
    return $oResponse;



    Also popular now: