php - Correct using of a namespace in mvc
one text
I have an engine of MVC. I need to create an instance of the class depending on URI, i.e. if a user enter mysite.ru/main - creating an instance of MainController. All Controllers are locating in the corresponding directory and using autoload (psr-4). Here is appearing a problem: I can't to connect this class in advance and my way to avoid this problem has failed:
use App\Controllers as Controller;
namespace Core;
class Route {
static function start() {
$name_of_controller = .. // Find this name (It will be MainController for example)
$instance = new Controller."\\{}" // <--- this code don't working
}
}
How to solve this problem?
Source