Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the best practice for creating method functions in PHP MVC?
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p>Here are the two examples I am referring to.</p> <p>Method 1</p> <pre><code>function register(){ $first_name = $this-&gt;input-&gt;post('first_name'); $last_name = $this-&gt;input-&gt;post('last_name'); $email = $this-&gt;input-&gt;post('email'); $password = $this-&gt;input-&gt;post('password_1'); $this-&gt;user_model-&gt;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-&gt;db-&gt;query($sql, array($email, $password, $first_name, $last_name)); return $register; } </code></pre> <p>Method 2</p> <pre><code>function register(){ $this-&gt;user_model-&gt;register_user()); } function register_user(){ $first_name = $this-&gt;input-&gt;post('first_name'); $last_name = $this-&gt;input-&gt;post('last_name'); $email = $this-&gt;input-&gt;post('email'); $password = $this-&gt;input-&gt;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-&gt;db-&gt;query($sql, array($email, $password, $first_name, $last_name)); return $register; } </code></pre> <p>I have removed a lot of the validation code and what not to simplify the matter so hopefully you get the idea.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload