What is the best practice for creating method functions in PHP MVC?

I wonder what is considered best practice when transferring information from a controller to a model. More specifically, I am creating a user registration model in a user class that requests certain information, such as email address, name and password.

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

Here are two examples I'm talking about.

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 deleted a lot of verification code and that didn’t make things easier, so I hope you get this idea.

+3
source share
2 answers

POST . , POST . , - , , , - (CSV), , POST.

,

+2

$_POST ( ) Model: , .

webservice, - : , POSTED .

- , , HTTP- ( HTTP-, ); , : Model.

+2

All Articles