Jump to content
Larry Ullman's Book Forums

Chapter 2 - Modularizing A Web Site Question


Recommended Posts

I am slowly working my way through the book trying to not peek too far ahead. I have built the chapter 2 modularized site example and found it to be very interesting. My question is more of a theoretical one I guess. I understand the basic concept of MVC...well I think I do. I understand OOP conceptually, for the most part anyway.

 

Where I think I am getting confused is that this bootstrap system looks like a MVC implementation of sorts. The modules can be called views, the index.php makes up a controller and separate db files for database operations make up the models.

 

I was thinking that the book was going to build upon this bootstrap in subsequent chapters, but it does not revisit it at all. It left me wondering the best way for me to use it with my current knowledge without coding a hodge-podge of concepts.

 

Since I am not ready for a "full on" major OOP project just yet, would it be silly to code a pseudo MVC application using procedural php and this bootstrap system as the base framework? It seems like a good idea at the moment, but as I learn more I realize I have coded a few WTFs that with new found knowledge, I am able to refactor my code base and save some head scratching by seasoned php developers.

 

Am I on the right track with this thinking? Could I call this a MVC implementation or is it just another way of organizing the code base and not to be confused with MVC?

 

Link to comment
Share on other sites

In my (limited) experience, I feel like there are a million different flavors of MVC, and it really comes down to how each person defines MVC as per what they're most comfortable with.

 

For example, at my current workplace, there is a strong preference towards a very heavy model, which contains just about every property and method necessary for any view you want to create. As a result, views are very, very light and trivial to change around.

However, others might argument that that approach is borderline MC (minus the V), and not a good division of labor.

 

I guess my point is that in the end, you should play around and see what works for you. If your coding pattern makes it easy for you to code something, and more importantly, easy to change around as need be, then you're probably on the right track.

 

As such, I like your idea of attempting MVC on a smaller project first to try it out. I say go for it. Also, don't worry about procedural vs. OOP. Again, whatever works best for you is what you should go with. I find that with smaller projects, OOP is quite often overkill.

 

Good luck.

  • Upvote 1
Link to comment
Share on other sites

 

In my (limited) experience, I feel like there are a million different flavors of MVC, and it really comes down to how each person defines MVC as per what they're most comfortable with.

 

That is what I am noticing, there a lot of descriptions and outright opinions as to what a "proper" MVC implementation is. I have read some white papers that left me dazed and confused. I think it is best (for me) to not over think it and just do it with a smallish project.

 

I am starting to get a lot of paying jobs now and I am trying to come up with a consistent way of doing things. I need to start thinking in terms of a "reusable code base". These are smaller projects and I agree that trying to "OOP it up" would definitely be overkill. However, they lend themselves to a MVC implementation very well. Then, after I am comfortable with my MVC framework, I will venture into OOP if it seems appropriate to the specific project.

 

I started using PhpStorm by JetBrains as an IDE and love the ability to start a full HTML5 boiler plate application (Php Storm imports the latest version automatically) with a couple mouse clicks, drop my shiny new bootstrap files into the project and be on my way to a solid MVC implementation in less than 60 seconds.

 

Thank you HartleySan for your time, as always I really appreciate your input.

Link to comment
Share on other sites

Yeah, I know how to feel, and I'm glad to hear that you're starting to get paying gigs. That's great. I hate to say it, but you might have to change your screen name, because you're no longer just "another noob".

 

Anyway, what I do these days is keep a folder of code snippets that I can use to solve various problems. For example, I have a code snippet for how to perfectly center a div on the screen both vertically and horizontally using only absolute positioning and not knowing the width or height of the div.

Those sorts of code snippets are very useful, and they're the kind of thing you're not going to remember unless you do them a lot. Naturally, I have PHP code snippets too for doing things like various kinds of cURL requests, a solid login script with good quality authentication, a script for setting up a DB transaction, etc., etc.

 

So in that sense, I definitely keep a hold of reusable code, but it's often not something I can just copy and paste into my new code and forget about it, but rather stuff that I've heavily developed and tested in the past and I don't want to forget it. Looking at the code snippets allows me to quickly jog my memory and figure out how to solve a problem. Once you know how to do something, the time it takes to actually type out the code is quite trivial, I think.

I also frequently bookmark Stack Overflow questions/answers. That can be super useful. I've also taken to asking lots of questions on Stack Overflow these days. I'm amazed at how many knowledgeable and helpful people there are on that site.

 

Anyway, I just wanted to share my approach to keeping a reusable codebase that works for me. As you said before, everyone's different, and whatever works for you best and gets the job done is what you should do.

 

Best of luck, and don't be a stranger around here.

  • Upvote 1
Link to comment
Share on other sites

Since I am not ready for a "full on" major OOP project just yet, would it be silly to code a pseudo MVC application using procedural php and this bootstrap system as the base framework? It seems like a good idea at the moment, but as I learn more I realize I have coded a few WTFs that with new found knowledge, I am able to refactor my code base and save some head scratching by seasoned php developers.

 

I think that's a good idea, and I've done the same thing when I had to refactor a procedurally coded site recently. 

Link to comment
Share on other sites

 

That's great. I hate to say it, but you might have to change your screen name, because you're no longer just "another noob".

 

Yeah, but it will remind me where I came from. I will be around here as long as Larry has this forum up, it is one of my favorite places on the web.

 

 

I think that's a good idea, and I've done the same thing when I had to refactor a procedurally coded site recently.

 

Thanks Antonio, I will press onward.

Link to comment
Share on other sites

 Share

×
×
  • Create New...