Hello there,
I´ve been reading a lot lately about MVC architecture (Model-view-controller) and PAC architecture (Presentation-abstraction-control).

I´ve also red some very useful posts around here that talks largely about this MVC vs. PAC issue.
Those posts seem to be a bit old (2005 and 2006 mostly), but I think that applies for Drupal versions up to 6.x. I think Drupal 7.x will be different, as it incorporates OOP.
1. Drupal as a MVC Framework?
2. Drupal supports the MVC pattern out of the box
3. Does Drupal 5 has a MVC architecture?

Of course, I´m not a programmer, so it´s pretty hard for me to get things straight in the first approach, so, I´ve search for some other material that could help me to understand this.
These are the most interesting resources:
1. Drupal as a MVC Framework?
2. MVC vs. PAC
3. Interactive Application Architecture Patterns
4. MVC Architecture vs. PAC Architecutre

So in few words, I manage to get this:

1. MVC is a very simple yet very adequate paradigm to develop software in general. But for web applications it might not be the best architecture. (I don´t know why, though)

2. Drupal doesn´t use MVC architecture, it´s more a PAC. Yet, I´ve found posts that say that Drupal can use the MVC architecture.

I must add here that I´ve recently found that Drupal can work with PHPCake, that supports MVC architecture.
This is accomplished using the Drake module (5.x.dev version).
Here is the post that discuss about it.

Anyway, I think this is an interesting issue that deserves to be talked and discuss again, because people are working with the 7.x version that, as I understand, will have some major changes in this special issue, and all those posts that I´ve found are pretty much old.

I´ve started searching for this topic, when I asked myself if PHP5 could work with the three layer architecture. And I´ve found terrific material. It´s in spanish, but very interesting. I post them here just as reference (they explain mostly what is exactly three layer´s design):
(I thought that if PHP5 could work with a MVC architecture, maybe Drupal could do it with some work)

1. Programacion en 3 capas con PhP y MySQL??? se puede???
2. Charla: NYI2: Desarrollar en 3 capas en PHP es posible
3. desarrollo en 3 capas, PHP UML
4. php desarrollo en tres capas
5. Desarrollar en Tres Capas…
6. Desarrollo en 3 Capas .NET
7. Aplicaciones en capas
8. Programación por capas
9. PHP5: Diseño en 3 capas y problemas con subdirectorios

Anyway, I wanted to have all MVC-PAC-Drupal related stuff in one post so it would be easier to find out some material in the forum, as there aren´t any good up to date stuff here.

Hope this helps newbies, and or as a reference material. And mostly start a discussion about MVC-OOP projects within Drupal.

Rosamunda
www.ligadelconsorcista.org

Comments

styro’s picture

then just don't bother worrying about this stuff. It doesn't make any difference, Drupal has it's own architecture and the more you worry about differences between it and other architectures, the less time you have to actually learn Drupal itself.

Drupal 7 won't become an MVC based system as that would practically be a complete rewrite with no additional benefit and make all the current documentation outdated. The changes that happen in each new release are usually limited to specific subsystems - the overall architecture changes little if any.

Generally the only people that talked about Drupal and MVC together are just running through a hypothetical intellectual exercise by seeing how if they squint a lot they can twist one architecture to fit into another. Either that or they just think because something has 3 identifiable layers you can call it MVC. Either way it is just navel gazing for "architecture astronauts".

I note there doesn't seem to be as much Drupal is MVC talk since Larry Garfield wrote his post pointing out that Drupal was actually PAC and not MVC. So thanks to Larry for that :)

--
Anton

Rosamunda’s picture

I´ve readed that Drupal 7 would introduce some OOP features, and I thought that it would/could introduce a change in its structure.
Anyway, as you´ve said, Drupal has it´s own architecture.

The thing is that I don´t think that Drupal´s architecture (PAC, hibrid or whatever) could be properly called a framework for creating web applications or web services.
Drupal *is* an excellent web application itself (I truly love it!), but I think it cannot be used as a framework for creating other things that sites. Complex ones.

And I don´t quite understand *why* is that. Is it because it doesn´t have a MVC architecture? Is it because it was born as a CMS and cannot *mutate* into a framework? Wikipedia thinks it *is* already a framework.
I know this isn´t the topic of the first post, but I must confess that this last question was the one that made me look for all this MVC discussion in the first place.

styro’s picture

Something doesn't need to be OO or MVC to be a framework. Something doesn't need to be MVC to be completely 100% OO either.

Drupal 7s database access will be more OO than previously as the underlying PHP libraries have shifted to OO. But in general the way you access databases will still be roughly the same (eg no full on ORM layer yet). And an OO based layer for SQL won't change anything architectural - Drupal will still have modules and themes that work the same way overall, and roughly the same menu system and Form APIs etc.

The difference between Drupal and say Django or Rails is the level they work at.

Django and Rails are lower level frameworks in my opinion - they work at the level of controllers answering an HTTP request, a database model returning some data and a template formatting some results. Plus they also have a bunch of nice libraries to help you create other functionality.

Drupal is a higher level framework that provides ready built site components (eg users, roles, content nodes, comments, tagging, themes etc) that focuses much more on an extensible plugin architecture for content driven applications.

Rails and Django etc are good for building an entire application from the ground up. They supply useful libraries for building and integrating higher level components. But to get something like Drupals extensible architecture, it is up to you to design and code your own extensible plugin architecture and to build/integrate the higher level components. eg you could build a high level Drupal like framework to sit on top of a lower level framework like Rails or Django - in fact this is exactly how Plone (the high level Drupal like framework) works by sitting on top of Zope (the lower level Rails/Django like framework).

Whether you choose a high level or a low level framework depends on what you want to achieve and how well each framework fits what you want. But high level or low level - they are all still frameworks capable of building complex applications.

--
Anton

Rosamunda’s picture

Thanks again Anton!
I think I´m getting to sort of *understand* this.

It was really useful your explanation because, as I´ve readed some more discussions about this issue, I don´t think there is plenty of material about Drupal as a Web App Framework out there. And the discussions that exists around here are not the final word in any way, because some people thinks Drupal can do absolutely everything; and some others think that Drupal is definitely flexible enough to do anything, but there is also a lot of structural overhead. (If you're using significant portions of Drupal's functionality compared to what you are writing from scratch then Drupal is a good choice. The further away you go from Drupal's existing functionality or paradigms (eg. Drupals nodes don't model your content well), the more you will be fighting Drupal rather than taking advantage of it. [1]).

I other words, Drupal *IS* a framework *BUT* with certain limitations. Of course as you´ve said, it´s still a framework capable of building complex applications.

Rosamunda

styro’s picture

Drupal is a flexible framework capable of building just about anything, but if you stray far away from it's strengths (content driven sites or community sites) then you might be better off using something else. Just like anything else has its own strengths and weaknesses.

It probably comes more down to do with how much you DON'T want Drupal doing rather than how much you DO want it doing.

--
Anton

kjarli’s picture

Drupal is not a framework, but a CMS... Yes, you can always use Drupal as a Framework. Nevertheless, if you want a framework, you should use a proper one like Zend Framework or Symfony. Symfony has lots of features Drupal has, but in OOP with easier use.

Unlike said in first post, MVC is used in web development!

All proper frameworks use it. MVC is a design pattern/principle. It's literally separating your view (html) from your controller (where your actual actions emerge for your page) and your model (your classes to get/set data or do whatever it must to create something). I've seen the hooks Drupal uses from the menu, the callbacks. This doesn't feature nice routing though. Nor do you have any nice request data, no templates you can manipulate etc.

What I've seen in Drupal doesn't make me happy... There is no structural organized setup. It's just a bunch of collaborating functions that manipulate data. Yes you can use the functions provided etc.. Except that you can't reuse anything.. Want another method of writing down an input field? Go write yourself etc.

Oh before I forget, why the hell do you use stdClass with like user or nodes? Why?? Why not just an array? What's the use of an object in an application where no objects are used? Arrays are faster anyway, if you use an object as if it's an array, it has no use.

Either make it completely OOP for PHP 5+ or stop major versions as PHP 4 is not used anymore. Well, shouldn't be used as it is an historical release.

You can't really say that Drupal is OOP, as OOP stands for Object Oriented Programming, it can't even be OO as in Object Oriented, because it is not Oriented on Objects! Yes you can use some objects, yes you can use proper OOP methods, but that doesn't make it OOP...

This might sound negative to you, but don't get me wrong, Drupal is a great CMS system, but no more. If you want to create an application, don't use Drupal as if it was a Framework, there are plenty of great frameworks for this, With my 2 favorite Zend and Symfony. Drupal should be used as a CMS.

styro’s picture

I probably shouldn't have bothered replying, but...

Your reply seems to be a random assortment of inconsistent statements that have no particular relation to the previous comments, and seem to be more of a brain dump of your frustrations.

Drupal is not a framework, but a CMS... Yes, you can always use Drupal as a Framework.

So you can use it as a framework, but it isn't a framework?

It certainly seems to match the definitions here:
http://en.wikipedia.org/wiki/Software_framework

Unlike said in first post, MVC is used in web development!

Where did anyone claim otherwise?

All proper frameworks use it.

So a framework that doesn't use MVC isn't a proper framework?

You seem to be fixated on "framework" meaning "MVC web application framework".

Hell, even the wikipedia page on web application frameworks talks about CMS frameworks and Drupal in particular:
http://en.wikipedia.org/wiki/Web_application_framework

You can't really say that Drupal is OOP...

Who even said that?

This might sound negative to you, but don't get me wrong, Drupal is a great CMS system, but no more. If you want to create an application, don't use Drupal as if it was a Framework, there are plenty of great frameworks for this, With my 2 favorite Zend and Symfony. Drupal should be used as a CMS.

Things aren't black and white - there is no well defined boundary between a web application and a content driven web site. It is a continuum, and different frameworks are suited to different parts along that continuum. I said as much in the comment you replied to.

And (just to be as cranky as you were) if you really want a great web application framework, ditch the PHP toys.

--
Anton

kjarli’s picture

So you can use it as a framework, but it isn't a framework?

Correct. Despite of what I've read on the Wikipedia and other websites (which is user contributed and not always right), Drupal is not a Content Management Framework. I don't see any framework parts in Drupal. It's just a set of slow collaborating functions, which you can't even properly extend.

So a framework that doesn't use MVC isn't a proper framework?

I never said that, I said that all proper frameworks use MVC.

Things aren't black and white - there is no well defined boundary between a web application and a content driven web site. It is a continuum, and different frameworks are suited to different parts along that continuum. I said as much in the comment you replied to.

True, but I don't think Drupal is the best for any of those functions unless you know you are not going to build modules... (or use them, RAM suckers they are)

And (just to be as cranky as you were) if you really want a great web application framework, ditch the PHP toys.

Yes, there are better languages .NET is much faster etc...