The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

(Beginner) How many parts of my application should know the app-object and is it correct to have mw for every validation?

Luca's Avatar


03 Sep, 2015 08:46 PM

Hello Slim-fans,
I just want to ask two beginner questions:

1) I'm using my own little MVC pattern right know - I asked myself whether my models (objects like products, users, payments, etc.) should know the Slim's app object. All of them require my database object that is stored within the app-object but for me it feels wrong to give all of those objects access to the entire app-object (that contains configurations etc.).

2) And is it a good practise to have for every form submission a own middleware that validates the input?

Thanks for Slim & thanks for your time
Some regards!

  1. 1 Posted by Rob Allen on 04 Sep, 2015 08:13 AM

    Rob Allen's Avatar

    To answer your first question, no the domain objects within your application should certainly have no knowledge of the application object. Pass the DB instance into the constructor of the objects that need it. Look into dependency injection as a way to do this.

    As for the second one, it's up to you :)

  2. 2 Posted by Luca on 04 Sep, 2015 02:25 PM

    Luca's Avatar

    Hello Rob!
    Thanks for your answer. So how have you solved the second point? What way do you prefer and what should my middleware look like?

    Thanks for your time!!!
    Regards :)

  3. Luca closed this discussion on 17 Oct, 2015 11:59 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac