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,
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,
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.
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.
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.
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
Framework Agavi utilizes really great MVC approach and beautiful OOP design. One of the best fw on the market IMO.
ModelI 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.
ViewView 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.
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):
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
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.
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.
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.
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