Jump to content

Dynamically calling method via url


macross

Recommended Posts

So i have an url routing class set up. I wan to call method via url so it would look something like this: http://www.mysite.com/index.php/Class/Method/Parameter. I was able to instantiate class like this:

 

$controller = new $this->UrlPath[0];

 

But i can't call method the same way

$controller->$this->UrlPath[1]();

Is there a way to call method with an array?

Link to comment
https://forums.phpfreaks.com/topic/245335-dynamically-calling-method-via-url/
Share on other sites

It's pretty hard to tell without seeing your design, but I have my router return a command object which has class and method as properties. I would then do something like...

 

$class = $command->getClass();
$method = $command->getMethod();

$obj = new $class;
$class->$method();

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.