This is a discussion on "Mvc" within the PHP Forum section. This forum, and the thread "Mvc are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Mvc
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
Mvc
Q. for you web guru's.
When building a site, do you use the MVC method that is sometimes talked about out there. A friend of mine uses it and I found it difficult to understand. This may be becasue I do not understand classes. |
|
|
|
||||
|
Re: Mvc
The MVC method is highly beneficial.
Breaking your code into three manageble areas is a good idea that allows for higher flexibility. Having database processing, HTML output and algorhythms all mixed up in one file makes it very hard to change one independently. To break it down into an easy to understand idea: M - The model. The backbone of your program, the way you arrange your data, the way you perform actions on it. V - The view. The output and what is seen, the displaying. C - The control. The conrol takes the model and sets it up for the output. Set your scripts up so these all work by themselves and you will have a very manageable code. Hope that helps. Cheers,
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
|||
|
Re: Mvc
Thanks for this
What key areas would you say I need to embrace/learn in order to really get to grips of working this way. |
|
||||
|
Re: Mvc
LOL, I think I already outlined my liking of OOP but objects and classes are definitely the best way to get this sort of abstraction happening.
Say you have a script that shows user information from the database. In the output script, you mix HTML and the output from controller objects. These objects are separate from the output and you just echo the results. The controler objects themselves perform operations on the data from your model objects. The model objects again are separate from the controlling objects. This allows you to change the output/operations to get output/data to be used in operations without having to alter the other layers in any way. Say you want to change the background colour of the page on a user preference basis. Don't fill your output page with conditionals, instead call an object method backgroundcolor = "', $userPreference->backgroundColour(), '" The class that built userPreference (controller) can then do the conditional processing to determine what colour to output and it does this by working with the data from a user class that has data (the model)... Hope that helps, but abstraction is very graceful and I am passionate about it... lol , like you couldn't tell.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
|||
|
Re: Mvc
I use cakePHP which is a MVC framework. It makes things a lot more organised, especially when working on large projects.
I'd suggest you do some basic work with classes, it will save you a whole bunch of time and headaches in the future! |
![]() |
| Thread Tools | |
|
|