Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Confusion about use of business logic inside controller classes

I know that in MVC the model layer or business logic is supposed to be separate from the rest of the application, and the controllers are just supposed to handle requests and responses and output different data to the views depending on user input. However, it is necessary to use models inside controllers, so I don't know I am supposed to do that without hard coding things. Let me use an example. Suppose I have a LoginController class:

class LoginController
//handle control of the login page view

And an Authenticator class actings as the model that connects to the database and handles the business logic:

class Authenticator
    private $db;

    public function __construct(PDO $db) {
        $this->db = $db;

    public function login($username, $pass)
        $user = User::getUser($username, $pass);
        $_SESSION['user'] = $user['id'];

At some point I am going to need to instantiate the Authenticator class inside the LoginController and call the login() method. But this would be hard-coding encapsulated business logic into the controller. Is this even a good practice? What is the right way of including or calling the model and its methods inside the controller?