Hi
How do I call a class method when the name will only be clear at runtime? I am sending all requests to index.php and parsing the url from there. the url would be formatted like this:
http://www.mysite.com/controller/method/queryString
I get it to load the controller but don't know how to load the method in that loaded cotroller. I tried this:
Language: PHP
//the controller loads, I put an echo in the constructor to make sure
${$controller} = new $controller;
//action is the method part of the url
if($action != "") {
if ((int)method_exists($controller, $action)) { //this evaluates to true and finds the function
$controller->${$action}(); //but then an error here
} else {
echo "not a valid function"; //this executes when I delete the function from the controller
}
}
say for example this is my url htt p:// localhost /portfolio /main / bob
then it calls the main controller but doesn't call the bob function. this is the code for the main controller which is just to test to see if the framework loads classes.
Language: PHP
class Main extends Controller {
function __construct() {
echo "this is an instance of main<br />";
}
public function bob() {
echo "You called?";
}
}
----------------------------------------------------------------------------------------
int get_random_number() {
return 4;
}