macross Posted August 21, 2011 Share Posted August 21, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/245335-dynamically-calling-method-via-url/ Share on other sites More sharing options...
macross Posted August 21, 2011 Author Share Posted August 21, 2011 Solved my problem using implode() function. Quote Link to comment https://forums.phpfreaks.com/topic/245335-dynamically-calling-method-via-url/#findComment-1260068 Share on other sites More sharing options...
trq Posted August 21, 2011 Share Posted August 21, 2011 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(); Quote Link to comment https://forums.phpfreaks.com/topic/245335-dynamically-calling-method-via-url/#findComment-1260069 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.