I have a larger application with a Frontcontroller in php that handles incoming ajax requests. I am thinking about a good way to handle Action->Method mapping, this controller is in charge of instantiating other classes and executing methods there.
The switch is just getting too big and it's ugly. I was thinking about creating an array and simply doing:
if(in_array($action, $methodmap)){
$methodmap[$action]();
}
But not sure of how efficient that would be or if there are any other better alternatives, performance is important since this controller handles a whole lot of incoming requests.
Thanks!
You could create a simple routing system.
index.php
And a directory
controllers/
where you store all your controllers. E.g.controllers/test1.php
When accessing
index.php?request=test1
,Test1->index()
would be called, thus output