4 Replies - 1107 Views - Last Post: 30 October 2008 - 04:33 PM Rate Topic: -----

#1 jstephens  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 214
  • Joined: 07-November 05

PHP Applications / Which paradigm

Post icon  Posted 29 October 2008 - 06:54 PM

I would like to start a discussion on what php applications use in regards to using straight php or a MVC approach. Seems like all the applications that I am seeing are done in a mvc coding style. But I would like some opinions on if this is always the way to go? Or do you prefer not to use the MVC paradigm and just use php without a framework?
Is This A Good Question/Topic? 0
  • +

Replies To: PHP Applications / Which paradigm

#2 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 452
  • View blog
  • Posts: 811
  • Joined: 17-June 08

Re: PHP Applications / Which paradigm

Posted 30 October 2008 - 11:00 AM

It depends - what do you mean when you compare MVC and "straight PHP?"

I think there are 2 separate questions here:
1) Do you use an MVC pattern?
2) Do you use a third-party development framework?
The two are not mutually exclusive. MVC is just a design pattern, so you can certainly build a system based on it from scratch in "straight PHP." Likewise, there are a few non-MVC development frameworks out there, such as Prado, which is component-based in the style of ASP.NET. So they're two separate questions - the first is about the design of the system, the second is about the technology used to implement it.

As far a s third-party frameworks go, I can take them or leave them. If I'm starting from scratch, these days I prefer to use a framework, for the simple reason that it saves me having to write all the plumbing code myself.

For existing codebases, though, it depends. For instance, I have a hobby project that I'm currently updating to use a proper object-oriented MVC pattern. For that, I eventually decided to just write my own MVC implementation, because the app couldn't be easily adapted to any of the frameworks I looked at. I could have used an existing framework, but that would have required a lot more re-organizing of the existing code. With a custom MVC framework, I can more easily hack around my existing crappy design and improve things in a step-wise fashion without totally breaking the application.

As far as design patterns, I think it's generally pretty hard to go wrong with MVC. It's well suited to web applications and is pretty easy to implement in PHP, so I generally use it as the design of first resort. But if you want to use something like Prado, or if you have some other brilliant design in mind, that's fine too - it's not like MVC is the only valid option. The important thing is that you have an organized design and that it separates your application's concerns in a meaningful way. Pretty much anything is better than the spaghetti-applications you often see that have SQL, business logic, and HTML all right next to each other in a single file. That's no design at all.
Was This Post Helpful? 0
  • +
  • -

#3 jstephens  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 214
  • Joined: 07-November 05

Re: PHP Applications / Which paradigm

Posted 30 October 2008 - 11:28 AM

Thanks adahacker for the great answer and also breaking out the question better. Well after reading your post I can say I normally try and hide all my php functions in a file called functions and database in some config.php file.

Two things. One do you have any suggestions for books on design? And also how would I go about doing an MVC structure without a framework like cakephp or zend. Kind of like building my own MVC structure or is that more of a pain and I would be better off using an existing one?

I know you said that you prefer to use a framework but I also saw that you said you will do your own implementation on MVC. If you have any sites that have a good walk through on designing your own MVC implementation that would be a big help.
Was This Post Helpful? 0
  • +
  • -

#4 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 452
  • View blog
  • Posts: 811
  • Joined: 17-June 08

Re: PHP Applications / Which paradigm

Posted 30 October 2008 - 01:10 PM

As far as books go, I've never read any design books particular to PHP. If you want to read about design patterns in general, the so-called gang of four book is the the classic in this area. I also liked Design Patterns Explained, though I have to confess I didn't read the whole thing (I was too cheap to pay for it so I read a few chapters over coffee in Barnes & Noble). Head First Design Patterns is also quite well regarded, though I was personally turned off by the cutesy nature of the book. Of course, these books aren't written for PHP, so not everything in them will be relevant, but they still give you an idea of some of the patterns that are out there.

Concerning implementing MVC without a framework - you're right, it's basically the same thing as building your own. Doing MVC is a lot easier if you have plumbing code in place: abstract Controller and Model objects that you can easily extend, a front controller with a defined URL routing structure, a standard mechanism for dealing with views, etc. At the basic level, that's what an MVC framework is. Of course, when you roll your own, you can end up with something smaller and faster than the third-party frameworks because it doesn't have to be general enough for other applications to use. Plus you can customize it to your particular application and development style. Whether or not that's worth the extra work over using an existing framwork depends on your goals.

I'm not aware of any web sites with a walk-through of implementing MVC. However, you can just look at one of the existing frameworks out there if you want some ideas. I always recommend CodeIgniter, because it's relatively small and easy to understand. Once you understand how the MVC pattern works and the lifecycle of a page request in CodeIgniter, you should have a fairly good idea of where to start. Like a lot of design patterns and OOP concepts, MVC isn't that complicated once you "get" it, but it might take some studying to get into the right mindset.
Was This Post Helpful? 0
  • +
  • -

#5 jstephens  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 214
  • Joined: 07-November 05

Re: PHP Applications / Which paradigm

Posted 30 October 2008 - 04:33 PM

View PostAdaHacker, on 30 Oct, 2008 - 03:10 PM, said:

As far as books go, I've never read any design books particular to PHP. If you want to read about design patterns in general, the so-called gang of four book is the the classic in this area. I also liked Design Patterns Explained, though I have to confess I didn't read the whole thing (I was too cheap to pay for it so I read a few chapters over coffee in Barnes & Noble). Head First Design Patterns is also quite well regarded, though I was personally turned off by the cutesy nature of the book. Of course, these books aren't written for PHP, so not everything in them will be relevant, but they still give you an idea of some of the patterns that are out there.

Concerning implementing MVC without a framework - you're right, it's basically the same thing as building your own. Doing MVC is a lot easier if you have plumbing code in place: abstract Controller and Model objects that you can easily extend, a front controller with a defined URL routing structure, a standard mechanism for dealing with views, etc. At the basic level, that's what an MVC framework is. Of course, when you roll your own, you can end up with something smaller and faster than the third-party frameworks because it doesn't have to be general enough for other applications to use. Plus you can customize it to your particular application and development style. Whether or not that's worth the extra work over using an existing framwork depends on your goals.

I'm not aware of any web sites with a walk-through of implementing MVC. However, you can just look at one of the existing frameworks out there if you want some ideas. I always recommend CodeIgniter, because it's relatively small and easy to understand. Once you understand how the MVC pattern works and the lifecycle of a page request in CodeIgniter, you should have a fairly good idea of where to start. Like a lot of design patterns and OOP concepts, MVC isn't that complicated once you "get" it, but it might take some studying to get into the right mindset.


Yea I think you are right. That has been my major issue right now. I really don't understand MVC at a deep level. Cake seemed to be a little weird to me for starting out. I think I will start with codeigniter first then look at it and test it out. Then go from their. Thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1