The Developer Day | Staying Curious

Mar/09

20

Sample PHP MVC application

Every web developer probably at some point heard something about MVC unless he or she was living in a cave. I definately have heard and read a lot about it. I won’t probably lie too much to say that most people know that MVC is the nowdays defacto design pattern for web applications. Atleast for PHP it is.

If you have ever had interest in design patterns and did some research on them you may know that design patterns may be interpreted and implemented different every time one tries to. And MVC is no exception to this rule. In my own career path I have seen many projects that claim to implement the MVC design pattern. And if it actually doesn’t - it may be called a hybrid of MVC. As ridiculous as it may be I think because of the MVC hype and everyone trying to be able to claim “yes we use MVC” it is one of the most misunderstood patterns of them all. And because of this … There are a LOT and i mean a LOT of articles and blogs and forums trying to explain MVC the way it should be.

And I myself have read a lot of versions of these blogs and articles. And to be honest I couldn’t answer to you for example what a controller should do and should not do. Well ofcourse I know it shouldn’t contain any business logic. If you would try to research that you would probaly find people saying that the controller should initiate the model, do something with the model and pass the result to the view and render it. You can even find some examples..

But to some extent I find it all synthetic and not very realistic. Most examples are of the level of Hello World program. I think the devil is in the details. If you would try to find any sample php mvc applications you probably wouldn’t find much. There are a few very simplistic sample MVC projects but I don’t find that to be an eye opener that goes deep into details.

I think the PHP community needs such an example. I believe Zend Framework is a great start for MVC. But it isn’t enough. It still doesn’t show you how a real life model or controller would look like. What each part of MVC would do and would not. I believe that one good example is better than a thousand words. I feel trully interested to try and find the “Equilibrium” of the famous MVC design pattern. Don’t you?

RSS Feed

11 Comments for Sample PHP MVC application

halfer | March 31, 2009 at 3:47 PM

There are plenty of arguments raging over what should go where in the MVC paradigm, but I don’t worry about them. At the end of the day, the point of a framework - MVC or no - is to make the developer’s life easier for complex web projects.

If you want an example of a working MVC-based application, there are loads around - I am not sure the PHP community needs another one, though maybe more the merrier! I am a symfony fan, so would recommend Jobeet to you; however if you prefer Zend, or Cake PHP etc., there are sure to be downloadable examples for those frameworks.

Author comment by admin | March 31, 2009 at 4:20 PM

I would tend to disagree with that there are “loads around”. And also one should check the quality of these examples if they exist. I’ll definately take a look to Jobeet. I must admit i haven’t digged really deep trying to find Zend framework working MVC examples, but from first glance there’s not much to find.

Abhishek | November 7, 2009 at 12:54 AM

nice info dude, but i am still confused why to use mvc over conventional 3 layer archi

Author comment by Žilvinas Šaltys | November 18, 2009 at 11:50 PM

Could you elaborate more on what do you mean by “conventional 3 layer archi”?

Rudy de la Garza | June 5, 2010 at 2:00 PM

Žilvinas, I totally agree. I am looking all over the web for an open source PHP project (finished application, not framework) that implements MVC to try and learn more than A BLOG IN 20 MINUTES!!

Did you find a real world example?

Author comment by Žilvinas Šaltys | June 13, 2010 at 4:36 PM

Hi Rudy. Sorry for the late reply. No I wouldn’t say I have. I’ve wandered off to slightly different waters regarding domain driven design. I was thinking of trying to write one myself but I’m not sure it will ever happen. Let me know if you find anything interesting.

Thanks

Dave | November 8, 2010 at 3:21 PM

Hi,

Trying this mvc and I’m getting stuck in: “Why MVC, it seems more work?”
Am I seing things wrong???
Can anyone point me a better direction?

Dave

Author comment by Žilvinas Šaltys | November 8, 2010 at 4:30 PM

Hi Dave,

Depends on what you’re doing. MVC separates different application concerns. Such as your business, data model from the view and the controlling parts. If you’re doing something quick and dirty and you’re sure not to do any long term maintenance then don’t bother with MVC. But if you’re working on something long term (2 - 5 years) following MVC for your web apps will pay off for the extra development since your application will be easier to understand and maintain after a few years.

HTH. If you’re still struggling try reading more about the pattern and all your questions will undoubtedly get answered.

Reid Workman | March 22, 2011 at 8:14 PM

Hello Žilvinas,

Have you come across any sample applications that have served as a solid learning tool for PHP-based MVC frameworks?

Thanks

Author comment by Žilvinas Šaltys | April 7, 2011 at 11:21 PM

Hi,

Since I’ve written the post I haven’t done any further research. Had some thoughts to try and create something myself but so far didn’t do anything. Surprisingly this topic seems to attract a bit of attention. If you do find anything yourself please share.

Erwinus | February 15, 2013 at 7:15 PM

I think MVC is nice but get very complicated and messy when the project is growing. Actually, it is pretty old technique, i saw it first in codeignitor, a php framework. It is not a bad technique but i think there is a better way to do it.

I have developed a technique/framework that the template is the steering wheel inside the project and decides what to load or not. It is based on template merging and you can easily merge other content without the need to change the code or add some new code.

It is not like smarty, it is much different to that because it is not needed to mess with php code. For example, you can use easily the template outside the project without php or you can add it to another project based upon the same technique without changing any line of code!

This way of developing a website or webapp is much easier to create, very stable and easy to maintain or expand and to exchange and mostly without the need program php code. It also has an automatic device detection mechanism and can use different templates for different devices.

I don’t get that all techniques around overcomplicate things and also base solutions on writing code (and to start from scratch over and over again). IMHO this is the wrong way because you need to program or change the core of the framework and can introduce new bugs.

For example to handle your forms, many people write code over and over again to validate fields by creating new code. Most things working the same but looking different from project to project, why most people want to reinvent the wheel over and over again. I don’t get it that there is no framework around like mine.

The best way to use a framework is a framework that can understand html and handle most of the basic stuff for you. That can speed up developing new projects and it is easier to maintain or update.

Leave a comment!

<<

>>

Find it!

Theme Design by devolux.org