Answer the question
In order to leave comments, you need to log in
How to load controller for symfony router?
For routing on the site, I decided to use SymfonyRoute, tell me how to autoload the class, now there is this code:
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
try {
$routes = new RouteCollection();
$routes->add('pst_get', new Route('/pst/{suffix}', array('_controller' => 'Post::get', 'suffix' => ''), array('suffix' => '.*'), array(), '', array(), array('GET')));
$routes->add('pst_post', new Route('/pst/{suffix}', array('_controller' => 'Post::post', 'suffix' => ''), array('suffix' => '.*'), array(), '', array(), array('POST')));
$request = Request::createFromGlobals();
$context = new RequestContext();
$context->fromRequest($request);
$matcher = new UrlMatcher($routes, $context);
$parameters = $matcher->match($request->getRequestUri());
$request->attributes->add($parameters);
$attributes = $matcher->match($request->getPathInfo());
$controller = $attributes['_controller'];
$response = $controller();
return $response;
} catch (ResourceNotFoundException $e) {
$proxy = new Proxy();
$proxy->setConfig($_config);
$proxy->run();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question