E-mailing in MVC, the final frontier...

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

alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: E-mailing in MVC, the final frontier...

Post by alex.barylski »

Can you explain in terms I can understand how a transaction script is more re-usable than a domain model? Eh, what does Fowler have to do with this? No ones playing the zealot card but you here.
Who said anything about transaction script. There isn't a single mention of transaciton script...I am simply saying that thin controllers and heavy models are not always the ideal solution. Sometimes the reverse is true. In fact, in most cases it makes sense to have light weight controllers and models, neither of which carry the brunt of logic...I personally have no single method more than 30 lines of code...so neither argument even applies to my development style.
Fowler have to do with this? No ones playing the zealot card but you here.
Because he usually finds his way into conversations on here...and it's tiring...that was my bad...he was/has not been mentioned...but when I argue...i'm bring my own insight to a disscussion...perhaps some of which has been learned from others...but my arguments are my own...not anyone else's.

So during disscussion when someone constantly quotes Fowler on something as subjective as application design...ugh...I've grown to dislike that guy solely based on the fact that some repeat everything he says verbatim, without a second thought, like they are robots or minions in his army. No offence to anyone...I realize that is my own ignorance and what he says is probably worth listening too (and I do -- I just wouldn't admit to it publically).

If am zealous, at least it's in favour of my own experience and opinion and not blindly following what someone else says. ;)

Again...I believe in the human spirit and team play (there is no I in team after all) but I also believe in individual thought and expression. Citation proves nothing but the ability to read. Although I do agree that it's an important of debate and research and developement, so I am being a hypocrite. :P

Cheers,
Alex
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: E-mailing in MVC, the final frontier...

Post by josh »

"fat controller" = transaction script. Why reword what can be cited? You are the one assuming that people who quote him are ignorant.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: E-mailing in MVC, the final frontier...

Post by alex.barylski »

I'm not sure if it was me that started it...

However this conversation (for the last 4-5 posts) has connoted a "My weiner is bigger than your weiner" and is not resulting in anything constructive.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: E-mailing in MVC, the final frontier...

Post by Eran »

Like I said, unless you guys are stuck in a bubble developing toys and never have a need to share data among other applications, then go a head and make your controllers single line invocations and your models fat as hell...but when you wrap that model with a web service and invoke it from a desktop application to render some results...you might find yourself refactoring the models. I've been there.
Wow, pretty harsh accusations. You're assuming way to much, my friend.
A model is a domain entity - it is relevant to the domain of an application. Reusing models in several applications must mean that they share a very similar problem domain. A User model in a hospital management application is nothing like a User model in a online poll system.

All the arguments I make here are from my own experience. I used to write fat controllers which looked like a bunch of procedural transaction scripts (as jshpro2 refers to them), but gradually logic had been transferred to the models as I improved my refactoring techniques and found better ways to encapsulate and reuse logic. The thin-controllers / fat-models idiom is not a dogma, it is something I found from experience to be the most effective design in every application I developed. I admit to not having much desktop software development experience, but I do have plenty of experience integrating against desktop software. This design pattern has proved itself over and over again.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: E-mailing in MVC, the final frontier...

Post by alex.barylski »

Wow, pretty harsh accusations. You're assuming way to much, my friend.
It wasn't meant to harsh...but I do admit to being:

1. Tired
2. Frustrated

Apologies for any hard feelings. Before I read any more of your reply and possibly reply, I just wanted to make it clear that my ONLY point was that different scenarios call for different design...a file structure can dictatate whether one follows a fat model-thin controller, as much as requirements can push a project to have a gentle balance between both and in some circumstances the opposite.

For anyone to claim they know the best solution (Fowler or not) is like my claiming to the best. Entirely subjective, total personal and utterly useless... :)
model is a domain entity - it is relevant to the domain of an application. Reusing models in several applications must mean that they share a very similar problem domain. A User model in a hospital management application is nothing like a User model in a online poll system
Agreed...considering I read that really quickly...I assume we probably mean/understand the same thing...
All the arguments I make here are from my own experience. I used to write fat controllers which looked like a bunch of procedural transaction scripts (as jshpro2 refers to them), but gradually logic had been transferred to the models as I improved my refactoring techniques and found better ways to encapsulate and reuse logic.
Fare enough. I've (like I said above) have tried, fat thin and happy medium...in my own designs and experienced that mixture in other projects...in my experience...different strokes for different folks...they all have counter arguments which are equally as valid as the next, it really depends on the requirements.
The thin-controllers / fat-models idiom is not a dogma, it is something I found from experience to be the most effective design in every application I developed
At least you said "I" developed... :)
I admit to not having much desktop software development experience, but I do have plenty of experience integrating against desktop software. This design pattern has proved itself over and over again.
I started in DOS devolping transaction like programs (Input->Process->Output) and moved to Desktop development in VB with it's MVP paradigm...slowly graduating into the world of C++ and a more MVC design...then jumped into client/server and 2-3 tier application development with Perl, ASP and PHP.

So I have experienced the "evolution" of software first hand from many different paradigms...which is why I guess I am hard pressed to believe that thin controllers are the ultimate, best solution...in strictly web development...it certainly seems to the popular trend...but that doesn't give it any more weight as a best practice in my mind.

I always play devils advocate and it somehow turns into a flame war of sorts...I either need to learn how to take others comments for what they are worth or seek counselling. LOL

Anyways...hopefully no hard feelings...nothing hurtful was intended...just tired and frustarted...not with you but with a project and oddly enough...deciding whether to make a certain design fat or thin in controller/model. :P

Cheers,
Alex
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: E-mailing in MVC, the final frontier...

Post by Kieran Huggins »

I have a mail class available inside my controller code, since i only ever send mail when it's triggered by a request:

Code: Select all

// a fictional sign-up controller
 
// (do the regular sign-up crap here), then...
 
// build & send the mail
$mail = Mail::to( $user=>pretty_email() )
    ->from('Your all-powerful admin overlord <ninja@space.goat>')
    ->text( render_partial('welcome',TXT) )
    ->html( render_partial('welcome',HTML) )
    ->send();
 
if ( $mail->errors() ){ // returns an array if there are problems, else false
  // oh crap, store the error details in the session
  $_SESSION['flash']['errors'] = $mail->errors();
  redirect_back(); // (dies here)
}
 
// back in happy land...
redirect_to('home');
I suppose you could write a ->queue() method (instead of ->send() ) to defer sending in some cases. Would probably just wrap Swift anyway.

MVC enough?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: E-mailing in MVC, the final frontier...

Post by Eran »

At least you said "I" developed...
Of course, I can only speak in the scope of my own experience. Obviously there are always exceptions, but that are practices that have proven themselves to be generally useful and conductive to a good design. The fact they are popular doesn't in itself make them wrong.
hopefully no hard feelings...
None at all ;)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: E-mailing in MVC, the final frontier...

Post by josh »

PCSpectra wrote:Fare enough. I've (like I said above) have tried, fat thin and happy medium...in my own designs and experienced that mixture in other projects...in my experience...different strokes for different folks...they all have counter arguments which are equally as valid as the next, it really depends on the requirements.
And I was just asking what those strokes might be. No one said they found any "utopian" best way, except you. I asked if you would be as kind as to articulate your experiences. You say the thread is not becoming constructive. I propose it is because you are offering weighted opinions with little to back them up. I would argue that if you rethought out your approach, that most would be willing to hear out your arguments if you made them sensibly.

I could see email becoming a controller action, if you were writing an application where the action the user directly was able to request was for an email to be sent maybe.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: E-mailing in MVC, the final frontier...

Post by Christopher »

PCSpectra wrote:For anyone to claim they know the best solution (Fowler or not) is like my claiming to the best. Entirely subjective, total personal and utterly useless... :)
Always this same caveat from you which is simple not true. A claim of a best solution by someone like Fowler (or even pytrin in my book) is not of the same subjective value as anyone else's personal opinion. To say so is nonsense.
PCSpectra wrote:Fare enough. I've (like I said above) have tried, fat thin and happy medium...in my own designs and experienced that mixture in other projects...in my experience...different strokes for different folks...they all have counter arguments which are equally as valid as the next, it really depends on the requirements.
I think it would be more accurate to say different strokes for you, not folks.
(#10850)
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: E-mailing in MVC, the final frontier...

Post by Eran »

(or even pytrin in my book)
8O wow, what an honor! :) Fowler must be turning in his grave, if he were dead...

I agree with Alex that to some extent what we say is subjective. It is subjective since it is confined to our own experience which is not all encompassing. Also I agree that it's hard to claim something is the best since those things are always fluid and evolving.

Having said that, there are definitely practices which can be considered better than others, and a thin controller is usually better than a thick one, for the reasons I mentioned.

Alex, if you could bring examples of situations that most of the logic would be better suited in the controllers - and in which MVC is still the appropriate pattern - I would love to hear those.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Re: E-mailing in MVC, the final frontier...

Post by Luke »

Had I known my comment about fat models skinny controllers would have sparked such a heated debate, I'd have started another thread on the topic. That's not to say I didn't enjoy the discussion. :lol:

As for the question I actually asked about... I really liked the idea of using observers for this (which I believe was proposed by jshpro). E-mailing (at least in this system) happens as a side-effect of many actions. I'd prefer that these actions not need to know about sending e-mails. I'm going to give this some thought and let you guys know what I end up doing.

I also like the idea of queuing these e-mails to avoid the sending of these e-mails right away, instead relying on sort of a "unit of work" approach. What do you guys think?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Re: E-mailing in MVC, the final frontier...

Post by Luke »

Alright, I think for this application, I'm going to implement an event-based system. I will define several events throughout the application that I want plugins to be able to "hook" into.

Code: Select all

class AuthController {
 
    public function loginAction() {
        // .. snip
        $this->triggerEvent("PasswordReset");
        // .. snip
    }
 
}
Then, I will simply implement my e-mail system as a plugin. It will be initiated in my bootstrap file, along with any other plugins (for instance, for filtering my user input with htmlpurifier or implementing textile).

Plugins would look something like this:

Code: Select all

class NotificationsPlugin extends Q_Plugin {
    public function onPasswordReset() {
        // send e-mail to user
    } 
}
 
I still have some things to work out, but this is basically what I have in mind. I believe this is a relatively common solution for plugin systems, no?
Post Reply