LMSouq
general-dev AI Answered

How should a model be structured in MVC?

DI
Dietpixel
1 month ago
3 views
Problem Description
I am just getting a grasp on the MVC framework and I often wonder how much code should go in the model. I tend to have a data access class that has methods like this: public function CheckUsername($connection, $username) { try { $data = array(); $data['Username'] = $username; //// SQL $sql = "SELECT Username FROM" . $this->usersTableName . " WHERE Username = :Username"; //// Execute statement return $this->ExecuteObject($connection, $sql, $data); } catch(Exception $e) { throw $e; } } My models tend to be an entity class that is mapped to the database table. Should the model object have all the database mapped properties as well as the code above or is it OK to separate that code out that actually does the database work? Will I end up having four layers?

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base