views:

3943

answers:

11

Hello,

Do you know some good Open Source project written in PHP that is a finest example of MVC and is just the best example to learn how to write a state of art project?

kind regards,

+4  A: 

I personally like the CodeIgniter framework: very straightforward and well documented. You will probably also want to look at Zend Framework. Joomla! 1.5 is written in MVC, but it is a content management system rather than a framework for starting projects from scratch.

jlleblanc
HelloThank you for answer, but I rather would like to see some code in action than pure framework.
tomaszs
Joomla 1.5 may be written in MVC, but I wouldn't call it the "finest example" of anything, by far.
ceejayoz
I second the vote for CodeIgniter. What do you mean by "code in action rather than pure framework" ... you can download the CodeIgniter framework and create your own hello world in seconds.
Toby Hede
I think what tomaszs is asking is to see a PHP open-source project OTHER than a framework (blog, CMS, forum, shopping cart, etc...) and written in MVC. Joomla! currently does this; I'd be interested in seeing others as well.
jlleblanc
Why would the most popular PHP CMS on the planet not be a best example of anything?
bucabay
@bucabay It might be a good project to study making an open source CMS successful, but it doesn't have the best code. Take a look at WordPress. It's very successful, but I nearly died when I opened the hood to make a modification.
alex
A: 

I'm working on a cake project right now and it's my first PHP project that I've written (professionally) since programming or 10 years. It actually seems pretty simple and intuitive to understand, and from what I've heard it's modeled after Rails so at least it's creators had a pretty good understanding of what a good open source MVC implementation should look like.

It is how-ever more then just an MVC project though; it's an entire web programming framework so if you're looking for an MVC implementation that would work on top of some other framework then it may not be the right choice for you.

matt_dev
+1  A: 

Diving into any large project might be overwhelming as far as a learning experience goes. A large extensible application/framework will have a lot of confusing special cases & over-generalized solutions, points for extension and so on. All of these things can be overwhelming and confuse the idea of what a 'good' design is - the sorts of generalization that are made to make a framework useful to a large number of different applications would, if viewed as part of a self-contained application, be nightmarish examples of overengineering.

If you really want to learn from studying other people's code, your best bet would be to study smaller, stand-alone components (such as PEAR modules or something like LightVC) and see how (and why) they do things differently as well as the relative benefits of each approach.

Most applications don't really need a full-stack MVC with a robust ORM layer (not to mention that a full-blown ORM system tends to promote the "one object, one table" mentality). You can get surprisingly far with page controllers, some simple logic to separate page-logic from presentation & a handful of models that use a decent DB abstraction layer - and for smaller projects, often finish earlier.

Sean McSomething
+2  A: 

When it comes to simplicity and learning the basics yourself, I totally enjoyed a tutorial on rolling your own that lived here: http://www.phpit.net/article/simple-mvc-php5

Unfortunately, the site's admin seems to have gone AWOL.

It is still available in the internet archive:

http://web.archive.org/web/20080128233521/http://www.phpit.net/article/simple-mvc-php5

DGM
+3  A: 

Framework Agavi utilizes really great MVC approach and beautiful OOP design. One of the best fw on the market IMO.

Model

I doesn't tie in to concrete ORM - It uses abstraction model instead (It is very useful e.g. when u need to change persistence layer from database to web service) which holds all domain logic (and leaves controller/actions relatively clean). Of course it doesn't force you to anything. If you want to use Propel/Doctrine/PDO inside the controller there is nothing in your way.

View

View layer is very pragmatic. It uses OOP to distinct logic of different output types (HTML and JSON for example). How about templating system? It is only the tool for view. U change it anytime and use Smarty, PATemplate or plain PHP (there is a way to do that simultaneously, thanks to layering the output - different layer, different template system).

There is much, much more of course. I really encourage You to read the tutorial. Its not finished yet, but will give you conception how Agavi works.

There is one very usefull resource i forgot about. The video of PHPLondon talk on Agavi.

Alan Bem
+5  A: 

There are quite a few PHP MVC frameworks out there. It might be worth some time reading up on the MVC design pattern (or meta-pattern) before looking into a specific framework or project, because a good many of them seem to put domain logic into the controllers and use models as little more than database accessors, which is contrary to the MVC principle.

Views should contain display logic, controllers should contain input logic, and models should contain domain logic (the heart of the application). In the end, you should be able to remove, add, or re-implement the controllers and views to have different manipulations of the application without having to rewrite anything that isn't input or output specific. That's the benefit of MVC.

Here are some of the areas where some of the MVC examples slip (not usually the fault of the frameworks themselves):

  • Views don't know about models. In traditional MVC, views are often observers of models and access models to update their state.
  • Controllers contain domain logic. In MVC, controllers should only contain logic specific to interaction with the interface, but some PHP frameworks give examples where they put all logic in the controllers and don't even use models. In this case, if you re-implement the views and controllers, you're rewriting the entire application!
  • Models are little more than DB accessors. This is related to the above. There seems to be a misconception that models are DB wrappers, but they are domain logic wrappers and should contain code used to manage and manipulate data, not just the data itself.

Studying the patterns involved in MVC before diving into examples will help you be aware of any such issues. It is possible to use most frameworks appropriately, but a lot of examples will have you putting a lot more code into controllers than into models. There are also many interpretations of MVC, which is why some call it a "meta-pattern."

Here's an interesting rant relating to this: Crazy guy e-mail

Sydius
A: 

Hehehe, guess what!
Mike "Crazy Guy" Seth is involved into Agavi development :)

Sydius... it is exactly as you said - in Agavi, model is not AR, Table Data Gateway etc. Basically its just good old plain PHP object (like POJO for Java) with some fw tie-in's (context initialization) and logic designed by your own hand.

Alan Bem
+1  A: 

Zend Framework.

There are video tutorials on their site that help a lot if you've never used MVC frameworks (plus it's the "official" php framework). I gave cake a try a couple years ago but I didn't catch on. Zend really made a difference for me to jump on the MVC wagon.

jdsushi
A: 

I found this tutorial very helpful when I was scratching my head over MVC.

But if I were you as soon as I get my head around it, I'll move to a already built MVC framework.

saint
A: 

Without to mention who is the best PHP MVC frameworks:

If you are a beginner, you can begin with CodeIgniter to understand the principle.

If you want to advance, you can use cakephp,

If you are pro and you have a big project, you can use Zend Framework.

Amirouche Douda
+1  A: 

This is an old topic I know, but I just found it on Google so as long as it's getting indexed I would like to add:

If you want to see a GIANT piece of working MVC code check out Magento, which is built on the Zend Framework.
magentocommerce.com

Also, I am quite fond of the Yii PHP Framework, which uses the MVC pattern nicely and has some good documentation and nice example Blog app.
http://www.yiiframework.com

thaddeusmt