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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:09:01+00:00 2026-05-20T15:09:01+00:00

I am wondering what is considered best practice when passing info from a controller

  • 0

I am wondering what is considered best practice when passing info from a controller to a model. More specifically, I am creating a user registration model within a user class that asks for certain info such as email, name, and password.

I am wondering if it is better to put parameters within the model function and pass them that way or if is better to just call the function and use the $_POST variables for the query.

Here are the two examples I am referring to.

Method 1

function register(){

    $first_name = $this->input->post('first_name');
    $last_name = $this->input->post('last_name');
    $email = $this->input->post('email');
    $password = $this->input->post('password_1');

    $this->user_model->register_user($email, $password, $first_name, $last_name));}

function register_user($email, $password, $first_name, $last_name){
    $sql = "INSERT INTO users (user_id, email, passwd, first_name, last_name, registration_date, confirmed, confirmation_code, banned)VALUES (NULL, ?, ?, ?, ?, '".date('Y-m-d')."', 'no', '1fg455675', 'no')";
    $register = $this->db->query($sql, array($email, $password, $first_name, $last_name));
    return $register;
}

Method 2

function register(){
    $this->user_model->register_user());    
}

function register_user(){

    $first_name = $this->input->post('first_name');
    $last_name = $this->input->post('last_name');
    $email = $this->input->post('email');
    $password = $this->input->post('password_1');


    $sql = "INSERT INTO users (user_id, email, passwd, first_name, last_name, registration_date, confirmed, confirmation_code, banned)VALUES (NULL, ?, ?, ?, ?, '".date('Y-m-d')."', 'no', '1fg455675', 'no')";
    $register = $this->db->query($sql, array($email, $password, $first_name, $last_name));
    return $register;
}

I have removed a lot of the validation code and what not to simplify the matter so hopefully you get the idea.

  • 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-20T15:09:02+00:00Added an answer on May 20, 2026 at 3:09 pm

    You shouldn’t be accessing your POST variables from your model. This would make your model less reusable since now they rely on POST data to work. For example, at some other point if you needed a method to do the same thing, but you were getting your data from some other source (CSV) you wouldn’t be able to use the same model because you’ve tied it in with POST.

    Try to decouple them when you’re working with such a structure

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

Sidebar

Related Questions

No related questions found

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.