70

I need some help from more experienced programmers. I want to improve my MVC skills. But I could not find a good tutorial on Google for MVC. Google always gives "MVC for beginners".

I understand what MVC is and I can make it, but I'm not experienced enough to do something practical in OOP.

If anyone knows a good object-oriented tutorial for MVC, please direct me to the right place — I'm looking for good links, books etc.

tereško
  • 58,060
  • 25
  • 98
  • 150
Ivan
  • 5,139
  • 11
  • 53
  • 86
  • start with the codeigniter tutorial from ellis labs http://ellislab.com/codeigniter/user-guide/index.html – Nishant May 03 '13 at 10:10
  • Youtube has a few good tutorials on MVC it might be worth having a look, there's a guy who does a 10 part tutorial on using CodeIgniter also which may help. CodeIgniter is simple to use when you know the idea behind MVC! – Ryan May 03 '13 at 10:10
  • you question needs rephrasing, are you looking for a particular type of tutorial on an implementation of MVC, something like ASP.NET MVC or are you just looking for theoretical more academic explanations of the pattern. – krystan honour May 03 '13 at 10:11
  • 2
    I know realy good CI framework. I have cms based on CI. CodeIgniter code like intricate as spaghetti – Ivan May 03 '13 at 10:12
  • I think he wants advice on how to learn enough about the structures/patterns of MVC concepts to make his own framework similar to CI etc. – Dave May 03 '13 at 10:18
  • 7
    @Dr.House , actually CI is one of two worst frameworks in PHP. Alongside with Cake. It does not implement MVC or any other MVC-inspired design pattern. It relies on global state, contains PHP4 artifacts, break all of SOLID principles and completely ignores SoC. – tereško May 03 '13 at 10:18
  • 7
    If you want to learn about MVC CI is one of the worst choices. You are far better of reading [this user's top answers](http://stackoverflow.com/users/727208/teresko). – PeeHaa May 03 '13 at 10:22
  • There is a big difference between coding a framework like CodeIgniter, and knowing enough to use CodeIgniter. – David Houde May 03 '13 at 10:24
  • What about Symfony MVC pattern? – Ivan May 03 '13 at 10:28
  • 4
    [Fabien Potencier – Symfony is NOT a MVC Framework](http://object-oriented-php.com/2011/10/fabien-potencier-symfony-is-not-a-mvc-framework/). Frameworks do not implement MVC. Your code does. – tereško May 03 '13 at 10:37
  • 1
    symfony 1 has some good tutorials, and certainly offered a good way to structure your web projects. This has been replaced by Symfony2, which removed a number of singletons and context objects, and replaced then with a dependency injection approach. In terms of best practices, I think you would gain a lot from looking at tutorials for either. (Note however that requests for tutorials and very generic advice does tend to be off-topic here, though it looks like you'll get the answer you need anyway!). – halfer May 03 '13 at 10:38
  • 10
    @tereško, web partisan indeed! I say this constructively: I notice your statements are frequently this abrasive (above, and in your comments to redreggae) and could do with an approach less likely to cause offense. For every successful open-source project, there are people who put their heart and soul into it, and sweat and tears too I should think! Symfony 1 was, whether you believe it meets today's level of development maturity or not, a great framework with a busy eco-system around it. Short version: be critical in a positive way, but don't rain on people's work. – halfer May 03 '13 at 20:16
  • 8
    Again, delete votes. __Yes__, this question seems to be non-constructive. But, __no__ - it should not be _deleted_. Leave it _closed_ - and that's enough. That is because: it contains __very helpful__ answer. – Alma Do Apr 29 '14 at 06:12

2 Answers2

257

Links, that contain PHP-only materials, are marked with php for easier identification.

You cannot even begin to delve into MVC before you have comprehensive understanding of OOP. That include OOP practices (dependency injection, unit testing, refactoring) principles (SOLID, SoC, CQS, LoD) and common patterns (and no, singleton is not an object-oriented pattern).

MVC is an advanced architectural design pattern, which requires solid understanding. It is not meant for beginners or for tiny "hello world" applications. One uses MVC to add additional constraints to the codebase, when simple adherence to OOP practices becomes too loose to control the codebase.

The best I can suggest for you would be to begin by expanding you knowledge regarding object oriented code:

The two lectures above should cover the basics. And then move on to:

When you understand all that was explain in this series, you can expand on:

Also, I would strongly recommend for you to read (in this order):

P.S.: you might also take a look at this book (cautiously, because it has issues): Guide to PHP Design Patterns php

tereško
  • 58,060
  • 25
  • 98
  • 150
  • Like the google talk ones because in the context of testing. Thanks for the list. – whereismydipp Sep 12 '13 at 07:28
  • @tereško this is one of the Best set of links which I have never read before Thank you very much for links . Is it possible to provide an explanation on actual reason for unit testing in php. I just wanted to know the importance of unit testing in frameworks by using tools such as phpUnit or Jenkins etc . Can we ignore this ? . I am asking this question because when I am writing code I often get a feeling that I am writing code to make sure I could use php unit easily to test its functionality . So it takes more of development effort when using phpunit . – Aravind.HU Sep 30 '13 at 05:55
  • 1
    First of all, Jenkins is a continuous integration tool. Different subject. As for unit testing - no, you do not **need** to use it. It shouldn't take more time for you to write code, that can be tested. If you write good OOP code (no global state, dependency injection where necessary) then the ability to test it will be just a side effect. And, if you were to write tests, it would require additional time. [This lecture](https://www.youtube.com/watch?v=Jr8jAK86Uf0) might explain what are the benefits and how to write those tests. – tereško Sep 30 '13 at 06:27
  • 4
    Thing is, when you develop without tests, the workflow goes like this: *you write some code, you upload it, then you fill in some data in different forms or click around and see if it work .. then you repeat*. It takes time to each time fill in the data. Unittests let you have predefine list of input and expected output so that you do not have to fill in that 50-field insurance form for the 100th time, just to test, if validation on 32nd field works correctly. And every time you find a bug, you just add a test with data that replicates that bug and the output that actually should be. – tereško Sep 30 '13 at 06:27
  • 5
    Another thing that unit tests do is - prevent you (or some overeager co-worker) from removing bugfixes in the name of *"optimization"*, just because somebody does not know or cannot remember "why there is this strange 3rd condition in IF statement?". If you remove something that breaks the code, unit tests will probably pick it up. – tereško Sep 30 '13 at 06:28
1

What I recommend to you is a book about design patterns. Most of these books also cover the MVC pattern and the other patterns are worth to know if you building a complete framework.

One good book is PHP Design Patterns. I don't know if it exists in english but I would search for other books and compare the contents.

bitWorking
  • 12,485
  • 1
  • 32
  • 38
  • 1
    *Kapitel 4, Erzeugungsmuster, behandelt Entwurfsmuster, die eingesetzt werden, um Objekte zu erzeugen. Vorgestellt werden in diesem Kapitel das "Singleton-Pattern", das "Factory-Method-Pattern", "Abstract-Factory-Pattern" und das "Prototype-Pattern".* .. and in final chapter it covers PEAR. This does not seem all that promising. – tereško May 03 '13 at 10:46
  • @tereško so what? you think the book sucks because it covers the singleton pattern? – bitWorking May 03 '13 at 10:49
  • 7
    It's hard to tell (notice how I neither said that it "sucks" nor downvoted). I'm just saying that one should be careful reading it. Especially if take in a count the overall amount of crap in "php books". – tereško May 03 '13 at 10:55