Forum Moderators: coopster

Message Too Old, No Replies

Building a short simple MVC with an actual purpose?

         

JAB Creations

11:58 pm on May 23, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's a lot of talk about what an MVC is though every example I see looks bloated (non-framework examples forget about frameworks) and seems to serve absolutely no useful purpose. Here is an example of what I think may apply to an MVC though correct me if I am wrong. If you are processing the request to display variable (let's say $_GET['number']) that should be a number and it turns out to not be an integer (or statically define it as $a = 1; if you have to be strict about it) you would want to change the HTTP code from 200 to an HTTP client or server error...so you could do that even though you've compiled the page up to that point (though not sent the headers yet because of the presence of the MVC)...and then you could change what the output was as well as the headers before serving the content. Is that an applicable scenario for working with an MVC?

Once I have an applicable idea then writing a basic MVC script and evolving it over time becomes much easier when the goal of the code is solidified. The how does not count unless the why is well established and that is the problem I have with all the tutorials.

- John

g1smd

12:10 am on May 24, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You are correct about the headers. Another example is where you retrieve your records from the database first (before starting to send the HTML page out) because if there are no records for this request you would want to send a 404 header and the HTML page would instead show your page not found error message.

All the stuff I see about MVC is bloated waffle, and all the applications that use it seem to be horribly bloated too. Supposedly it is easier to follow the logic, but that's probably only true for the author. I can rarely follow other people's code, especially when they don't liberally comment it.

JAB Creations

12:32 am on May 24, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks G1, so in practice by what you've stated I already have an MVC to a certain degree. Yes, I try not to degrade other people's code though I won't say I know X Y or Z if examples aren't explained in the why context.

Since I develop solo I keep finding I comprehend things without knowing what they are called. My CMS (the server side aspect) determines if content exists and then prepares meta data else it preps for the correct HTTP code if it's not 200 (it presumes default meta, title and HTTP (404 by default)). It doesn't compile the entire page though it doesn't prevent headers from being processed/sent after the CMS file is executed (unless it's an HTTP 301 in which case I immediately use die() to prevent Gecko browsers from a bug where they hang if content is served with a redirect header). I also use the class associated with the CMS and constantly reuse the arrays and variables associated with it all the way to the end of each module that is dependent on it (e.g. blog, forums, private messaging) and to my understanding reusing code is object oriented whereas figuring out the same thing over and over is procedural.

So here is a question of clarification...

What is the difference between my CMS as an MVC where it handles the HTTP responses, title element and meta elements and an MVC that won't serve anything until you've processed all the way to the end tag of the html element? Would you refer to it as a partial MVC, a full MVC or something else? I do process certain things after ob_end_flush and the end tag for the html element, I suppose that might be considered post-processing? I do that to reduce the compilation time of course for clients. :)

I'll make a hypothetical situation; I code everything on my site except the search engine. The only problem that any user will potentially deal with is the fact that my host's MySQL service is constantly going down (I log all JavaScript, PHP and MySQL errors so I've very aware of what I consider constant downtime even if each instance is only a few seconds short).

So in this hypothetical situation let's say the last panel on the sidebar is unable to process information from the database because the MySQL service goes down. Currently that is past what my CMS handles and I could not currently serve an HTTP status besides 200 at that point. If I were to adapt my CMS/MVC model that I have now that would envelop everything that is processed what would the term for my MVC change to?

I'm very capable of doing this code wise though it looks like I need to figure out what I already know in practice before I try filling in gaps that don't exist apparently, e.g. terminology to coding practices. Thanks for your response. :)

- John