Posted by router:

class App { private $fileOrderManager; private $pageManager; private $routes = [ '/' => 'getIndex', '/admin' => 'getAdminPage', '/order' => 'save' ]; function __construct($fileOrderManager,$pageManager) { $this->fileOrderManager=$fileOrderManager; $this->pageManager= $pageManager; } public function run() { $path = parse_url($_SERVER['REQUEST_URI']); $method = $this->routes[$path['path']] ?? 'getIndex'; if(!method_exists($this, $method)) { return; // throw exception } $this->$method(); $this->pageManager->getIndex(); $this->pageManager->getAdminPage(); $this->fileOrderManager->save(); //$this->fileOrderManager->list(); } } 

Obviously, in this form, the method does not find it, the condition method_exist works and returns from the function. How do I set up to call methods from classes ($ this-> pageManager-> getIndex (); and mn)?

Thank!

    1 answer 1

    As well as it is told - the name of methods do not correspond to what is in $routes . The router, as it turned out, should have a method that addresses the methods of managers (DB Manager, etc.). Those. The getIndex method of the router should contact the pageManager page pageManager and call the corresponding getIndex() method

    that is, the output was:

     function getIndex() { $this->pageManager->getIndex(); }