I'm building my own micro MVC framework with only the absolute core functionality. My router will call the controller depending on the request method (GET or POST), and if the called action isn't supported it will default to the index action.
Is my approach correct? Any suggestions for improvement?
abstract class Controller
{
protected $action;
protected $params;
public function __construct($action, $params)
{
$this->action = $action;
$this->params = $params;
}
public abstract function GET();
public abstract function POST();
}
class IndexController extends Controller
{
public function GET()
{
$action = $this->action;
$this->$action();
}
public function POST()
{
$this->GET(); //no POST support
}
private function index()
{
$indexView = new View('index');
$indexView->welcome = 'Welcome!';
$indexView->render();
}
}