MVC Madness

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
ben.artiss
Forum Contributor
Posts: 116
Joined: Fri Jan 23, 2009 3:04 pm

MVC Madness

Post by ben.artiss »

Hi everyone,

I've really hit a roadblock recently... I'm so confused with all this MVC stuff I'm about ready to burst so thought I'd ask you guys your opinions! :) I followed a tutorial yesterday trying to get my head around building an MVC framework from scratch, but someone keeps telling me to stop re-inventing the wheel (whereas I beg to differ in that I'm LEARNING!). So I stopped and seriously considered what he was saying: maybe I really should use something that's already been built?

I mean, I've used Joomla! quite a bit (which is what brought the MVC pattern to my attention), and since, I've basically been trying to make a cut down version of it. I'm quite comfortable with OOP now, but I'm really starting to think along the lines of "Perhaps I shouldn't be so condescending as to think I could do a better job of what people have already done".

Let's face it, who hasn't heard of the Zend framework? Surely it has something going for it? Would it be worth swallowing my pride and learning something that someone else has made or should I persevere and make my own?

Incidentally, if you know a better approach than MVC I'd be really interested in hearing about it!

Thanks,

Ben
Paul Arnold
Forum Contributor
Posts: 141
Joined: Fri Jun 13, 2008 10:09 am
Location: Newcastle Upon Tyne

Re: MVC Madness

Post by Paul Arnold »

I'd recommend just building an application with codeigniter.
If you do it properly, you'll start to see the way the M,V and Cs interact with each other.

Alternatively, follow the Jobeet tutorial with Symfony.

http://www.symfony-project.org/jobeet/1_2/Doctrine/en/

No matter how much people try to explain it all or how much reading you do, nothing will teach you more than building something yourself.
ben.artiss
Forum Contributor
Posts: 116
Joined: Fri Jan 23, 2009 3:04 pm

Re: MVC Madness

Post by ben.artiss »

I like the attitude man (that's what I wanted to hear :P)! I was of the impression it would be a bit of a waste of time to be able to use an MVC framework without knowing what's happening behind the scenes. Given that this is a theory and design section... is MVC arguably the best method for building a dynamic website?
User avatar
inghamn
Forum Contributor
Posts: 174
Joined: Mon Apr 16, 2007 10:33 am
Location: Bloomington, IN, USA

Re: MVC Madness

Post by inghamn »

MVC's a reasonable pattern to start from for architecting a system. Keep in mind it's a very general, vague pattern, and it doesn't map cleanly to the web. Not that there's another pattern that maps any better. Everyone implements MVC differently.
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Re: MVC Madness

Post by matthijs »

@ben.artiss: what do you think is MVC? what is it about, what do you think is important?
ben.artiss
Forum Contributor
Posts: 116
Joined: Fri Jan 23, 2009 3:04 pm

Re: MVC Madness

Post by ben.artiss »

What I want essentially is to end up with a base system which can be easily extended but has the major tasks out of the way, which is my impression of MVC. I really like the idea of separating code from appearance, and especially like the idea of never having to worry about database transactions, correct/valid input from users, user authentication etc. But most of all I really like the idea of once I build something to handle e.g. newsletters and feeds, I'll never have to build them again, merely implement.

My latest efforts have all brought me to the MVC method, i.e. single point of access, URL controlled and so on, but I'm just a little lost on how it all glues together. I think I need to read through a few more tutorials!

I mean, my previous attempts to separate different users was to have an enum field in the users table which determines the types of users; so if http://localhost/ was accessed I'd know it was a guest, or if http://localhost/admin was accessed I'd know to validate the user's session; but from what I've seen MVC doesn't work like that (unless you want it to?).

I've confused myself to a point of no return for now, must make a basic framework to understand it properly before carrying on! Does anyone know of handy tutorials?

Thanks,
Ben
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Re: MVC Madness

Post by matthijs »

Ok, that clears up some things. What you need to know about MVC is that it is about the concept of having a separation between the M (model), V (view) and C (controller). So it is about having a few layers in your program/application. Separating the three makes working with them easier and allows for reusability.

However, MVC is not about having a base system "which can be easily extended but has the major tasks out of the way". That is what is called a framework or library. Zend Framework, or Code Igniter, Symphony, etc are frameworks of different modules and classes which act as a base to develop your app on. They all do use the MVC concept, but that's only a small conceptual part of it

If I were you I'd start building something on top of one of the frameworks (code igniter seems to be an easy one to enter), so that it's easier to learn the basics.
ben.artiss
Forum Contributor
Posts: 116
Joined: Fri Jan 23, 2009 3:04 pm

Re: MVC Madness

Post by ben.artiss »

Excellent that makes me feel a whole lot better :D i thought i was starting to lose the plot on PHP all together! I'll give your suggestion a try and will no doubt try to customize it to suit my needs, but I think there is much to be learned before I'm "in control" again. I've been working on this cms for what feels like forever, and the MVC pattern just feels right for it, I just need to understand the behavior and order of things.

Thanks for your replies man.

Regards,
Ben
ben.artiss
Forum Contributor
Posts: 116
Joined: Fri Jan 23, 2009 3:04 pm

Re: MVC Madness

Post by ben.artiss »

Madness, I just had a watch of the video tutorials on the code ignitor website and it's put a whole different look on things: it explains what I was trying to do in the first place lol. Thanks a lot for the advice.
Paul Arnold
Forum Contributor
Posts: 141
Joined: Fri Jun 13, 2008 10:09 am
Location: Newcastle Upon Tyne

Re: MVC Madness

Post by Paul Arnold »

That's it, you get all these terms and concepts thrown at you and it's hard to get your head around them all because of all the jargon. When you finally get an explanation that you understand or start working with it you wonder what all the fuss was about.

CodeIgniter is a great place to start in my opinion.
Post Reply