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 6982015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:13:57+00:00 2026-05-27T18:13:57+00:00

I’m just wondering which one is better, or more recommended for processing form data.

  • 0

I’m just wondering which one is better, or more recommended for processing form data.

// Controller
// validation etc
$data = array('name'=>$this->input->post('name'), '... etc');
$this->user_model->insert($data);

// Model
function insert($data){
    $this->db->insert('users',$data);
}

or

// Controller
// validation etc
$this->user_model->insert();

// Model
function insert($data){
    $data = array('name'=>$this->input->post('name'), '... etc');
    $this->db->insert('users',$data);
}

I’m using the second method at the moment. Despite no problem for inserting, I have to say it’s not very suitable for updating. I end up having to create new methods to update only certain fields of a table. I’m thinking of changing to the first method. I’m just wondering whether anyone can help give clearer pros and cons of each method.

Thanks!

  • 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-27T18:13:58+00:00Added an answer on May 27, 2026 at 6:13 pm

    I agree that Models and Libraries should be doing most of the heavy processing, however I believe that Model and Library methods should be as re-usable as possible, and the Controller should act as traffic director, deciding which models to call and what data to send to them.

    So in your example, the former makes more sense. Think about it this way — isn’t it possible that you may want to add a user some other way, other than via form posts?

    Another option, if you want best of both worlds, create a wrapper function in the model:

    // Controller
    // validation etc
    $this->user_model->insert_from_post();
    
    // Model
    function insert_from_post(){
        $data = array('name'=>$this->input->post('name'), '... etc');
        $this->insert('users',$data);
    }
    
    function insert($data){
        $this->db->insert('users',$data);
    }
    

    Of course in this example it seems excessive. But in more complex applications you quickly benefit from being able to reuse functions that have established, predictable and tested results.

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

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I
I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6

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.