📜 ⬆️ ⬇️

Drupal as MVC Framework

“Software architecture” - these words usually scare most freelance web developers. 3-Tier, MVC, Singleton, Factory ... “Stop! stop it! why complicate things? ”- they would say to you in reply,“ Here we have, for example, Drupal — Temko was implanted, modules were twisted-tuned and, in principle, the site is ready. ”Indeed, CMS Drupal provides an excellent platform for rapid development, while demanding minimum amount of effort invested.

Many have probably heard of such a concept as “the ideology of Drupal” - this is exactly what made this CMS such a convenient and efficient platform. But perhaps few realize that the ideology is based on the well-known MVC pattern, or Model-View-Controller.


Drupal MVC
')
The MVC pattern (i.e. design pattern) consists of three interrelated elements: Model, View, and Controller. This separation into components allows us to distinguish between user interfaces, control logic and content.

The model is the actual content, data, reflecting the subject area and structured in accordance with some kind of scheme, for example, in the form of relational database tables (MySQL, PostgreSQL, MS SQL Server, Oracle). The so-called DB API (a set of functions for working with a database) is also part of the Model. In addition to the Model is the program code that defines the data types and their properties and relationships.
From the point of view of Drupal, the Model is a DB plus such modules as node.module, taxonomy.module, CCK. Other third-party modules, along with their main functions, can also supplement the Model with their own data types or functions of communication with the database.

The controller interprets the data entered by the user, performs state changes depending on user actions, manipulates the entities of the Model so that they can be turned into a View, and generally does everything so that the gears of the system spin. In Drupal, the Controller is the basic modules of the path.module type, the menu system, the hooks, the index.php file, which builds and loads the system, etc. Also, all logic implemented by additional modules is part of the Controller.

The view is responsible for displaying the Model to the user. In the case of Drupal, these are the final pages of the site, compiled by the Controller based on the visitor’s requests and the current Model. The presentation includes page templates written on the PHPTemplate engine, CSS style files, Javascript, which is responsible for fronts in the interface. Through the View, the user communicates with the site - the Controller only processes the HTTP GET and POST requests sent by the browser, interprets the URL, and then re-creates the View and sends it to the user's computer.

Fast and effective development of a site on Drupal is possible due to the fact that the described model allows you to divide the problem being solved into separate components, and ready-made solutions are offered for the implementation of each of these components. There is no need to invent your Model or Controller - please apply a proven scheme. It is often possible to get by with only minor changes in the View to create a full-fledged Drupal web application. But if there is a need to implement a specific logic or content structure, then it’s enough to implement your parts of the Controller and Model, adding or changing existing versions.

This approach has already proven itself in technologies such as ASP.NET, J2EE, Spring. Drupal , being a content management system, quite successfully adopted this experience, actually offering a full-fledged platform for creating any type of web sites based on the MVC architecture in the most common LAMP bundle (Linux-Apache-MySQL-PHP). Undoubtedly, this CMS has room for improvement, including in this direction, but today it can be used as a powerful tool for web development.

Ps. The author of the topic is alirasirin habrauzer , all advantages, if there is a wish, to her .

Source: https://habr.com/ru/post/56007/


All Articles