Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7600021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:48:30+00:00 2026-05-30T22:48:30+00:00

I know a controller does the controlling, and model does the database stuff. How

  • 0

I know a controller does the controlling, and model does the database stuff.

How far should the model go though?

If I have an array:

array( 'first_name' => 'Thomas', 'second_name' => 'Clayson', 'email' => 'thomas@email.com' );

And this is the mysql query I need to get out of it:

INSERT INTO `users` (`name`, `email`) VALUES ("Thomas Clayson", "thomas@email.com");

What should my model look like?

Take raw data and format appropriately

public function insertUser($details){
    if(!isset($details['first_name']) || !isset($details['second_name']) || !isset($details['email'])){
        return false;
    }

    $full_name = $details['first_name']." ".$details['second_name'];
    $email = $details['email'];

    $query = "INSERT INTO `users` (`name`, `email`) VALUES ('".$full_name."', '".$email."')";
}

Leave the formatting up to the controller and just take the input and put it blindly into db

public function insertUser($full_name = false, $email = false){
    if(!$full_name || !$email){
        return false;
    }

    $query = "INSERT INTO `users` (`name`, `email`) VALUES ('".$full_name."', '".$email."')";
}

Something else?

My problem is that I’ve got a lot of data to put into a table, so I don’t really want to have each field as a separate arg of a function. But then I feel that putting in an array of info into the model requires me to check each index and format appropriately anyway, so there’s not much point doing it in the controller as well. Seems like twice the work.

But then again, it doesn’t feel right doing it in the model either!

So what do other people do?

P.S. The question is based on (but by no means limited to) the codeigniter framework.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:48:32+00:00Added an answer on May 30, 2026 at 10:48 pm

    Here we go again …

    Model in MVC is not a class. It is a layer which contains objects with two kinds of responsibilities:

    • domain business logic
    • data access and storage

    Domain business objects should not have any clue where the data comes from or where it is stored. That means there is no SQL in domain objects, because it is quite possible that there isn’t even a database and all the information goes into some remote REST API.

    If you are using a database, then SQL would end up in the DAO’s ( usually implementing datamapper ).

    And formating is not responsibility of neither of domain objects , nor data access objects nor even controllers.

    Formating should happen in the Views, which are a full-blown objects in MVC, and not some anemic templates. View is responsible for presentational logic. It requests from the domain model layer what it needs.

    You really must look up what MVC Model2 is , and how it is different from MVP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know what view/controller do I have to use to obtain the same
What's the best way to know when my array controller that is bound to
I know this is extremely silly. I have a view controller that scans a
I just want to know how does error controller work for different module ,say
Does anyone know how to make rspec follow a redirect (in a controller spec)?
I know that the main (first) view controller does not unload until the app
does anyone know how to prevent the failing mechanism of link_to_unless_current? f.e.: I have
Does anyone know how to assign and then use a closure in a model/view
Does anyone know of a good way to start with a basic model but
In Short: Does any know a way from the base controller to get a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.