Is WordPress MVC compatible?

Some people consider WordPress a blogging platform, some consider it a CMS, some of them treat WordPress as a development framework. Whatever it is, the question remains. Is WordPress MVC compatible?

I read the forums and someone asked about MVC about three years ago. There were some positive answers and some negative ones. Although no one knows exactly what MVC is, and everyone thinks about it in their own way, there is still a general concept that is present in all discussions.

I have little experience with MVC frameworks, and it seems that something was not in the structure itself. Most MVCs are made by the programmer, am I right? Now, returning to WordPress, can we look at the main mechanism for rewriting (WP_Rewrite) the controller? Queries and plugin logic as a model? And what about themes? Or did I misunderstand?

Thank;)

+59
model-view-controller wordpress
May 18 '10 at 12:21
source share
9 answers

Wordpress itself is not archived in MVC, but within the framework of the structure, you can create very MVC-oriented themes and plugins. There are several tools that can help:

WordPress MVC Solutions:

WordPress.org MVC Threads Ideas and Trac:

+45
May 29 '10 at 18:35
source share

Wordpress is a kind of MVC. Anyway, this is a pull-type MVC layout, where View 'pulls' the data from the model. It does this in a very efficient way, instead of using many different objects, but it actually makes it easy to write patterns on the front panel in many ways.

It also gives views some degree of controller logic (thus, sorta-sorta MVC).

Lets do this: Wordpress gets the url. The wordpress kernel acts as a controller and determines what initial queries to start the database and by extension, what kind of load should be loaded (category view, single message or page view, etc.). He then sends this INTIAL request and sends it to the view file.

This view file may be a strict display of only the file or it may request additional information / requests outside the built-in. This is an MVC pull type in which a view displays data from a model instead of “pushing” controller data from the model into the view.

Thus, when the view sees the code loading the sidebar or widget area, it requests this information. However, which widgets should be there, determined by the controller, which looks at the model, which widgets are on the side panel, and then selects those that are installed to display on the current page, and returns them to the view.

The fact that every part of this object is not an object does not make it less than MVC. You can change the core of WP without (necessarily) changing anything about the topic. Similarly, as long as you use the built-in functions like "get_pages ()", the model and database tables can change while these functions still return the correct data. Thus, the model is independent of the view, and the controller is also independent (unless the view adds the controller logic to do more than the kernel usually does).

While you have a model object containing several methods, etc., such as WPModel :: get_pages ("blah blah"), and contain everything that way, there is still a fundamental separation of problems.

View: template files Controller: WP core Model: various functions that process specific data processing.

So far, names, arguments, etc. If they remain unchanged (or just add new ones), then the separation of problems is preserved and can be changed without disturbing others.

This is not a super-clean version of MVC (especially when hooks are involved), but at a basic level, it starts there.

And being a sequel about this is not bad, IMO. The request from the website is pretty much a continuation in its essence: it is a process with a clear start and end, and it just needs a procedure to process the request, receive data, package, and then skills. You can customize these steps with the objects and methods of OOP objects and layouts (which will simplify some things), or you can simply write many function calls and separate them this way. Class members, such as private variables, get lost this way, but depending on the needs of the application ... you might not care.

There is more than one way to do development, and WP sits on 20% of websites, so it does something right. Probably, something is connected with the fact that people should not study / memorize complex class hierarchies in order to get a database in order to answer the question "which pages are child pages of page x?" and handle this data. Could you do this with OOP? yes, but if Joomla is an example of how difficult it is to implement a complex user website with OOP, then WP will be faster and faster, and time is money.

+24
Jan 06 2018-12-12T00:
source share

As mentioned in the comments, MVC is an architectural design pattern, not a specific structure, and no, Wordpress does not match the MVC pattern.

There is a separation of representations (templates) from programming logic, but only in the interface, and not in the admin panel, and the general separation of representations and application logic is not necessarily related to MVC. The implementation of the MVC template usually implies some kind of object-oriented programming paradigm, while Wordpress is mainly implemented procedurally, with the usual SQL queries in PHP functions, therefore it does not have a real model.

+9
May 18 '10 at 12:48
source share

Just update this information with the latest information for people coming to it from search engines - the wp-mvc plugin http://wordpress.org/extend/plugins/wp-mvc/ goes a long way towards creating an mvc structure for plugin development. You can find out more here: http://wpmvc.org/documentation/70/tutorial/

+5
Aug 13 '12 at 20:19
source share

Just add to the list of options (I'm admittedly biased as the author) swpMVC is a full-featured, lightweight MVC framework inspired by Rails, Sinatra, Express and FuelPHP. It is fully documented, and while I used and enjoyed wp-mvc , I wanted the models to fill out the views themselves, including form controls for interacting with the specified models.

I combined this mainly to reduce the amount of controller code needed to build an application on top of WordPress, and the result is a very fast and efficient framework that works inside WordPress. Models are based on PHP Activerecord and 8 models are included for existing WordPress data types, including Post, PostMeta, User, UserMeta, Term, and several more. Modeling data is very easy thanks to the activerecord library, and I really enjoyed working with this card so far.

Also comes with underlining PHP and PHP Quick Profiler (as shown in FuelPHP.)

+4
Aug 20 2018-12-12T00:
source share

One of the topics that periodically arise in discussions regarding WordPress is the idea of ​​WordPress and MVC.

But the fact is that MVC is not the silver bullet of web development that we are trying to do. Yes, this is an amazing design template, and I personally think that it is suitable for a web application model like a glove, but not every platform or platform implements this design template.

Example: WordPress is not MVC.

And all is well. It seems to me that we need to leave the desire to try to throw it into our projects, especially if the WordPress template is not only sufficient, but also works well when used correctly.

"But I love MVC!"

So am I! In fact, I spent the last year working on a project that more or less mimicked the MVC architecture. A high-level example of MVC.

enter image description here

A high-level example of MVC.

For example:

Views were implemented using templates Controllers were implemented by a combination of using function names like create, read, update, destroy, delete, and so on (even though these functions were hooked into the WordPress API Models were functions also were called to validate and verify data prior to serializing the data. Again, this required that certain functions be hooked into WordPress to achieve the desired result. 

Finally, the rewrite rule set gave the application a clean set of predictable URLs in the format / people / update / 1 or / people / all. Which template uses WordPress?

WordPress implements an event-driven architecture (of which there are several options, such as the Observer template).

In short, you can conceptually think of it as the following:

 Things happen when WordPress is processing information. You can register your own function to fire when these things happen. 

Not too complicated, is it? A high-level example of event-driven patterns enter image description here A high-level example of event-driven patterns

When you start thinking in terms of the paradigm in which she works, and not try to make her work the way you want her to work, her release. This helps solve problems much easier.

The bottom line is: WordPress implements an event driven design template, so even if you try to implement MVC, you still have to use a hook system.

If you are not careful, you may end up trying to create the perfect architecture without doing your job, and thus find yourself so high in the software atmosphere that you will actually become an architecture astronaut. So, Youre Saying Avoid Design Templates?

Not at all! Design patterns serve the purpose because, above all, they basically give us solutions to previously and often solved problems. Use them!

But the point I'm trying to make is that we don’t need to try to get things to fit the pattern just because we like the pattern. This is not their goal. Instead, use the main template that your choice platform implements - in our case, an event-driven template, and then implement the templates where they are suitable (for example, dependency injection or something like that).

Otherwise, it is like trying to put your foot in a glove.

Provided (and fully copied: P) from: http://tommcfarlin.com/wordpress-and-mvc/

+4
May 22 '14 at 7:27
source share

RokkoMVC is a micro-MVC infrastructure designed specifically for WordPress. The project aims to simplify the functionality of AJAX in WordPress applications, as well as take advantage of all other benefits of using models, views and controllers for your theme.

+2
Jul 18 '12 at 21:50
source share

I recently created bash to create a plugin that uses a simple presentation control system, and I really liked the results, so I separated the template material into my own repo . It offers object-oriented controllers, locally passing variables to PHP templates, template fragments (templates in templates) and components (template fragments with their own control). All in two tiny classes!

Of course, I wrote this code, thinking that no other WP developer had addressed the problem before ;-) .

+1
Dec 18 '12 at 23:32
source share

This is far from mvc, there is nothing of the kind, like some, say, it is either MVC or not ... The fact that you write logic at the presentation level does not qualify it as an mvc structure. The reason people use this is that it's easy to learn, you don't have to be a hardcore php programmer, they are lazy.

0
May 8 '13 at 16:43
source share



All Articles