Page 2 of 3
Re: Minimalistic MVC Framework
Posted: Tue Oct 28, 2008 8:25 pm
by alex.barylski
If an application pattern (and MVC is the most widely used in the web-world) isn't used you are fully at the mercy and whim of however someone else 'feels' is the best way to organise and structure their application.
That is the idea...unfortunately everyone has a different idea of what exactly belongs in a model or view or controller...the basic definitions do not dictate but only suggest, so even in MVC designs I see code in weird places.
Re: Minimalistic MVC Framework
Posted: Wed Oct 29, 2008 12:09 am
by Christopher
PCSpectra wrote:That is the idea...unfortunately everyone has a different idea of what exactly belongs in a model or view or controller...the basic definitions do not dictate but only suggest, so even in MVC designs I see code in weird places.
First, I don't think people have very different ideas about what exactly belongs in a model or view or controller. Instead I think people choose, intentionally or unintentionally, to not implement both of MVC's separations.
Second, MVC is a pattern (I guess technically two patterns

) and does not specify an implementation -- so the code can vary and still follow the pattern.
Re: Minimalistic MVC Framework
Posted: Wed Oct 29, 2008 7:55 am
by panic!
PCSpectra wrote:If an application pattern (and MVC is the most widely used in the web-world) isn't used you are fully at the mercy and whim of however someone else 'feels' is the best way to organise and structure their application.
That is the idea...unfortunately everyone has a different idea of what exactly belongs in a model or view or controller...the basic definitions do not dictate but only suggest, so even in MVC designs I see code in weird places.
That's probably down to people not fully understanding the design pattern. I definitely agree that a fair amount of people will confuse what code goes in a model and what goes in a controller though.
I think it is generally accepted what goes in a model and what goes in a controller.
I definitely will say coming into an MVC based project will be way easier than someone who's coding to their own specification 95% of the time.
Re: Minimalistic MVC Framework
Posted: Wed Oct 29, 2008 11:09 am
by allspiritseve
panic! wrote:I think it is generally accepted what goes in a model and what goes in a controller.
Ha. I wish...
Where does validation belong? Business logic? Authentication? Does the controller give the model to the view? Does the view call the model directly? Is the db the model, or does it contain the model? Are templates views or just part of views? Does the separation between controller and view really matter? Is a front controller part of MVC? Nobody agrees on these questions.
Re: Minimalistic MVC Framework
Posted: Wed Oct 29, 2008 11:10 am
by crazycoders
Thats because it is not a coding standard, just a pattern. There are norms as to how to do it, but no standards.
Re: Minimalistic MVC Framework
Posted: Wed Oct 29, 2008 1:37 pm
by Christopher
allspiritseve wrote:Ha. I wish...
Your wish is my Command pattern...
allspiritseve wrote:Where does validation belong?
Not part of the MVC pattern ... can be in any of the three.
allspiritseve wrote:Business logic?
In the Model. I have honestly never heard and disagreement about that one. However, there may be some disagreement on the definition "business logic" or identification of that code.
allspiritseve wrote:Authentication?
Not part of the MVC pattern ... can be in any of the three.
allspiritseve wrote:Does the controller give the model to the view?
It can. People who say it can't do so for implementation reasons and not because of the pattern. The important thing is that the dependencies go the right way.
allspiritseve wrote:Does the view call the model directly?
Same as previous answer.
allspiritseve wrote:Is the db the model, or does it contain the model?
It is up to the programmer whether there are further separations within the Model. Following the proven 3-Tier, the DataSource layer would be below the Model layer. But certainly they could be combined. And certainly what we in PHP consider a lower level "DB" object could be used as the Model. I think you are looking for way too much specificity here -- the MVC pattern does deal with the internals of the Model, only its role and separation.
allspiritseve wrote:Are templates views or just part of views?
This is a common misconception because people think of templates as the template file and Views as code -- but they forget the template engine which is also considered part of the View code.
allspiritseve wrote:Does the separation between controller and view really matter?
Depends on what "matter" means (it is a non-technical term). Separation between the Controller and View is part of the MVC pattern -- so it is obviously considered important. Dependencies can go both ways. The C to V separation is considered less important than the M to CV layer separation. The CV separation promotes code reuse -- but that is always a programmer's call.
allspiritseve wrote:Is a front controller part of MVC?
Not part of the MVC pattern, but a Front Controller launching Action Controllers as the "Controller" is a very common implementation. It is a parallel solution that maps nicely onto MVC (many patterns have affinities like this).
allspiritseve wrote:Nobody agrees on these questions.
Oh yes they do, it's just that many are not part of the pattern or they have a preference for one of several implementations.
Re: Minimalistic MVC Framework
Posted: Wed Oct 29, 2008 3:17 pm
by allspiritseve
arborint wrote:Oh yes they do, it's just that many are not part of the pattern or they have a preference for one of several implementations.
My point wasn't that there aren't right answers to those questions, just that people don't agree on them. Whether they think things are part of MVC that aren't (front controller, authentication, validation) or mistake certain implementations for being the one true MVC (push view, pull view, M/V separation). I think you're giving people too much credit for these being conscious design decisions. The model is also complicated by misconceptions of the activerecord pattern, where people assume model = db, which may end up taking business logic out of the model and into the controller. I do agree with many of your answers, though. I just don't agree that everyone else agrees

Re: Minimalistic MVC Framework
Posted: Wed Oct 29, 2008 5:33 pm
by Christopher
allspiritseve wrote:My point wasn't that there aren't right answers to those questions, just that people don't agree on them. Whether they think things are part of MVC that aren't (front controller, authentication, validation) or mistake certain implementations for being the one true MVC (push view, pull view, M/V separation). I think you're giving people too much credit for these being conscious design decisions.
I think there is a difference between "don't know" and "don't agree". Certainly some people don't know some of the specifics about the MVC pattern. But when MVC is discussed they say "ok ... I see now" or "I prefer to implement it this way" -- not "I disagree".
allspiritseve wrote:The model is also complicated by misconceptions of the activerecord pattern, where people assume model = db, which may end up taking business logic out of the model and into the controller.
I think those misconceptions are broader misunderstandings. If you don't understand N-Tier and why your Business Logic should be in a separate layer from your Presentation code -- then you really cannot understand (or appreciate) MVC. That's not MVC's fault. But honestly, the layer separation between the Business/Domain Model layer and the Presentation layer is the greatest challenge for programmers. If you really understand that separation and can maintain it in your applications then you are an elite programmer -- I, for one, cannot and am not.

Re: Minimalistic MVC Framework
Posted: Wed Oct 29, 2008 7:34 pm
by alex.barylski
Not part of the MVC pattern ... can be in any of the three.
How do you mean it's not part of MVC -- if it can be done in either component?
I suppose that is accurate in the sense that validation is only a serious concern in web applications and therefore does not apply to classical MVC. I would argue that MVC is an ever evolving pattern. In web MVC (passive view) we do not usually have (or require) the same dependencies as classic MVC, for example.
Re: Minimalistic MVC Framework
Posted: Wed Oct 29, 2008 7:57 pm
by Christopher
PCSpectra wrote:How do you mean it's not part of MVC -- if it can be done in either component?
MVC is a set of dependencies and roles. Things like Access Control, Logging, etc. have little to do with that. They are things that can be done anywhere and are separate from the MVC dependencies. There is nothing that says that the M, V and C can't all be dependent on a Logging class for example. That in no way changes their dependencies with each other.
PCSpectra wrote:I suppose that is accurate in the sense that validation is only a serious concern in web applications and therefore does not apply to classical MVC. I would argue that MVC is an ever evolving pattern. In web MVC (passive view) we do not usually have (or require) the same dependencies as classic MVC, for example.
I disagree. The pattern has not really changed. There has always been an acknowledgment that some flexibility in the dependencies is necessary. It is a pattern, not a dogma. It is true that MVC implementations are ever evolving. Specifically, things like Active or Passive View make no difference to the dependencies in the pattern. The Model has no (or minimal/careful

) dependencies on the View.
Re: Minimalistic MVC Framework
Posted: Fri Oct 31, 2008 6:52 am
by panic!
allspiritseve wrote:arborint wrote:Oh yes they do, it's just that many are not part of the pattern or they have a preference for one of several implementations.
My point wasn't that there aren't right answers to those questions, just that people don't agree on them. Whether they think things are part of MVC that aren't (front controller, authentication, validation) or mistake certain implementations for being the one true MVC (push view, pull view, M/V separation). I think you're giving people too much credit for these being conscious design decisions. The model is also complicated by misconceptions of the activerecord pattern, where people assume model = db, which may end up taking business logic out of the model and into the controller. I do agree with many of your answers, though. I just don't agree that everyone else agrees

Just because MVC, isn't a pure catch-all solution doesn't mean it isn't the best there is at the moment. Which pattern do you think is better? Especially for new developers coming into an existing project? I would argue MVC is an almost ubiquitous standard which makes it far easier than just coming in someones project where anything could be anywhere? Which pattern is better than MVC in your opinion?
Sure there is some flexibility in the pattern, but that's no bad thing.
Re: Minimalistic MVC Framework
Posted: Fri Oct 31, 2008 2:01 pm
by Christopher
panic! wrote:Which pattern is better than MVC in your opinion?
I don't think better is the issue. I think it is appropriateness to the problems we face. Better/worse ignores that we must make choices and tradeoffs in our designs.
I think there is a general spectrum of implementations in web applications:
1) Transaction Script where the business logic, response rendering and request handling/program flow are all in one script, so:
M V C
2) N-Tier where the business logic is in one layer and the response rendering and request handling/program flow are all in a Presentation layer. This separation is the most important one:
V C
|
V
M
3) MVC where the business logic is in one layer and the response rendering and request handling/program flow are also separated in the Presentation layer, so:
V <-->
C
|
V
M
The above are all choices that depend on the problem at hand. For a simple contact page a Transaction Script is fine. For many simple pages that do not have code reuse potential then N-Tier is fine. MVC gets you to do the extra separations which is usually good because sites grow and the reuse benefits occur naturally -- rather than having to go back a rewrite things. Historically, MVC was a reaction/improvement to N-Tier but they still share the same core goals.
Re: Minimalistic MVC Framework
Posted: Sat Nov 01, 2008 10:05 pm
by VirtuosiMedia
Since the topic is a minimalistic MVC framework, what do you think one would have to include, bare minimum? And a related, but separate question: what would one have to include bare minimum for you to use it?
Re: Minimalistic MVC Framework
Posted: Sun Nov 02, 2008 12:04 am
by s.dot
I've never been able to implement a full OO design pattern into my applications. I have classes (config, database, basic user account, and a few others).
I then have a header.php file which instantiates stuff I will need on every page load.
Then I have a content file such as err, i dunno - view-online-users.php (for example)
then I have a footer.php
So my setup looks like this.
header.php
Code: Select all
require_once 'bootstrap.php'; //session_start(), $config object, $template object and $db object, and misc. functions file loaded in here
$tpl->assign('user', $_SESSION['username']);
$tpl->display('header.tpl');
content file
Code: Select all
$usersOnline = $db->query("SELECT count(*) FROM `users` WHERE `last_active` >= UNIX_TIMESTAMP(NOW()-INTERVAL 5 MINUTE)")
or die($db->error());
$tpl->assign('usersOnline', $usersOnline->result());
$tpl->display('view-online-users.tpl');
footer.php
All (ok, most) form actions are sent to a processing page using a post-redirect-get pattern.
So, in question: am I using (or using something resembling) any current design patterns? Or am I just off in the procedural/oop mix doing my own bastard thing?
Re: Minimalistic MVC Framework
Posted: Sun Nov 02, 2008 1:40 am
by alex.barylski
scottayy: Theres a face I haven't seen in a while.
So, in question: am I using (or using something resembling) any current design patterns? Or am I just off in the procedural/oop mix doing my own bastard thing?
You are achieving the template logic separation it seems but your controller and model could use further separation.
I would focus on creating models as they are probably the most prone to introduce bugs into an applications. While template logic is by far the most complicated or verbose, once a template is 'complete' the logic rarely changes only the HTML does. With that in mind, the model changes all the time as requirements change. You change the schema you update the model -- usually.
The idea is to separate the SQL into table data gateway functions and call those functions, which act or can be your model. All the business logic, like checking for duplicates, etc would be in the model as well.
Now when you change a table shema you know exactly where in your code the changes required are needed.