I know I can do this:
//Jquery
$.ajax({type: 'POST', data : {'action' : 'foo'}});
//PHP
if(isset($_POST['action']) && $_POST['action'] == 'foo')
{
function foo()
{
//yeah
}
}
But.. In a project I'm working on with a friend, he has set up the controllers to be able to have specific functions called using custom actions. For instance, say my view is using the controller of thing.php. From my Javascript I can just AJAX to a url like this:
'url' : 'thing'
So in this case, foo() would get called without a need for any ifs or switches (as far as I know)
To me, this is great and ideal but I'm not sure how it was set up. He isn't around for the holidays to ask so I'm asking you guys.
Do you know how this is achieved? We are using a pretty typical MVC architecture. Sorry I am a PHP novice. Thanks!
$class = new $classType(); $class->$actionName();or loaded with reflection (the last one is slightly slow but gives more information that maybe used in advanced pre-processing.