Welcome Guest, Not a member yet? Register   Sign In
Switching from procedural to MVC?
#4

[eluser]BrianDHall[/eluser]
I was in the same boat, and created nearly an entire project 'the old way' (non-MVC) after hearing about the concept of MVC and it took that process to really 'get it'.

Basically, when you are using the older procedural/functional way you tend to end up with "spaghetti code". If you want to change the template and redesign the site, is that a simple change of a template file even someone who doesn't know much code can do...or would it be a multi-day chore for you just to implement the new template?

You've probabably heard of "separating content from formatting" where you try to define what you want to say in HTML but leave the "how it looks" to CSS? Or perhaps "sepparating business logic from content" in code.

MVC is the next step.

You have your Controller, with your business logic, like "if you are an administrator show the member management page, and handle the form if posted".

You have your Models, which are more like "Here's the membership info...now do something with it" - so they handle manipulation of your data and the creating/retrieving/updating/deleting (CRUD) of it as well. So a User model often may have a login() and logout() function, and update_account_info() function, etc etc. This is where you can use ORM to automate much of these functions for you.

Then there are Views, which is basically your html templates with perhaps a little bit of display logic. So for instance you have your account creation form View, and your Account Creation Success View, your Home Page View, etc.

This organization matters once you've gone past, say, 10+ pages with considerable logic involved. With proper use of Functions, and objects/classes once you get into some OOP, MVC is a tool that allows you to eliminate spaghetti code, allow clean and easy to maintain/refactor/update/expand code even when your application becomes very large.

Once you build a significant project using these methods, you see just what a difference it makes. You'll look back on the stuff you wrote before and think, "it would be easier to rewrite that then have to figure out what the hell is going on again...".

You can still use the system wrong, and CodeIgniter is very loose - it'll let you do whatever you want. In my first project I partially kept to the system of MVC, but violated in quite a few places, and now on my next project I'm keeping much more faithfully to the system.

It's one of those things that just Matter.


Messages In This Thread
Switching from procedural to MVC? - by El Forum - 09-04-2009, 02:01 PM
Switching from procedural to MVC? - by El Forum - 09-04-2009, 04:31 PM
Switching from procedural to MVC? - by El Forum - 09-04-2009, 05:41 PM
Switching from procedural to MVC? - by El Forum - 09-04-2009, 06:18 PM
Switching from procedural to MVC? - by El Forum - 09-06-2009, 03:38 PM
Switching from procedural to MVC? - by El Forum - 09-07-2009, 03:04 AM



Theme © iAndrew 2016 - Forum software by © MyBB