When developing a system using MVC from scratch, does each controller need to be a class or can I simply use a file containing some functions that will be called according to the action sent by View?
Example, I have a controler for the "profile" view that displays user data and updates them if necessary.
include_once('model/usuario.php');
class Controller{
public $dadosUser;
function __construct($action = null){
if(empty($action)){
$user = new Usuario();
$id = $user->id;
$this->dadosUser = $user->loadUsr($id);
}
}
}
In this case, is it possible to change the value of $ action when instanciating a new Controller?
Another example is a generic file that I'm implementing as follows:
include_once('../model/usuario.php');
$action = isset($_POST['action']) ? $_POST['action'] : "";
if($action){
switch($action){
case 'login':login(); break;
case 'listar':getAllAqr();break;
default: break;
}
}
function login(){
$email = isset($_POST['email']) ? $_POST['email'] : "";
$pwd = isset($_POST['senha']) ? $_POST['senha'] : "";
$usr = new Usuario();
$usr->login($email, $pwd);
$id = $usr->id;
if($id){
header("Location: http://localhost/aldeia/dashboard.php");
}else
header("Location: http://localhost/aldeia/login.php");
}
Which of these two forms is the most appropriate?