Everyone understands mvc as he wills, but sometimes I do not, at all.
Currently the majority of my controllers look like this:
<?php
$input = $_REQUEST['field']
$model = new Model();
$status = $model->launchSpaceShuttle($input);
switch($status)
{
case Model::STATUS_LAUNCHED:
header('Location: Mars');
break;
case Model::STATUS_INVALID_INPUT:
echo "Please press the big red button correctly";
break;
case Model::STATUS_PILOT_IN_HANGOVER:
...
...
case etc.
}
This leads to the obvious question:
Is this how it’s supposed to be? Model’s returning status codes and controllers deciding how to display and what?
Because this very much conflicts with the theory about simple, short controllers that act as a really thin wrapper between the input device and the model.
bonus case: what about ajax requests if I’m too lazy to create a view ;
Ah, that’s easy. Just move the entire switch to a view file.
It’s the view’s responsibility to interact back with the user.
Redirecting from inside the view is just as fine.
Anyway in most frameworks the view file inherits the
$thisvariable which represents the active controller.Same regarding ajax requests.