Sk446
Sk446

Reputation: 1240

PHP MVC - Is it bad practice to use a model that doesnt directly relate to a controller of the same name?

I'm currently working on an MVC based PHP project. My script basically will be sending out some emails to clients, and it needs to pull an email template from the database. I've got a mail helper library which provides an interface into the SWIFT Mailer class. For the data related stuff (e.g pulling the email template from the DB) is it bad practice to use a new model (lets call it 'mail_model.php') even though there wont be a mail controller?

A quick overview of the structure:

CONTROLLERS - Client (some emails get sent here) - Invoices (some more emails get sent here)

MODELS - Client - Invoices - Mail

VIEWS - Client - Invoices

HELPERS/LIBRARIES - Clients - Invoices - Mail (interface for SWIFT)

(nb: this is just a dumbed down example)

So yeah, I really just wanted to see if this was a bid no-no or if its ok to be doing this. If its not, does anyone have an alternate way of doing it?

Thanks for your time!

Upvotes: 1

Views: 296

Answers (2)

thwd
thwd

Reputation: 24818

Actually there's no fix correlation from controllers to models.

Models abstract persistent strage (i.e. database) operations, and controllers handle requests.

A controller may use several models for some request and none for another.

Upvotes: 3

9miles
9miles

Reputation: 321

I don't personally see a problem with having a model that could be used by multiple controllers. But not sure if thats your question, as it's a bit confusing.

Upvotes: 1

Related Questions