Answer the question
In order to leave comments, you need to log in
How to get routes from database?
The project has a categories table that contains the entire site structure with links (in the alias field) and metadata. The called controller is specified in the action field.
How can I load all routes from this table?
Answer the question
In order to leave comments, you need to log in
I did this:
in app/config/routing.yml
# It must be the last
category:
path: "/{alias}"
defaults: { _controller: "AppBundle:Default:category" }
requirements:
alias: "[a-z_-]+(\/[a-z_-]+)*"
/**
* @ParamConverter("category", class="AppBundle:Category")
*/
public function categoryAction(Category $category, Request $request)
{
$id = $request->query->getInt('id');
if (null == $id) {
return $this->run('index', $category, $request); // indexAction
} else {
return $this->run('details', $category, $id); // detailsAction
}
}
private function run($actionName, $category)
{
$params = func_get_args();
array_shift($params);
$namespace = "\\AppBundle\\Controller\\". $category->getController() . 'Controller';
$actionName .= 'Action';
/** @var Controller $controller */
$controller = new $namespace();
$controller->setContainer($this->container);
return call_user_func_array(array($controller, $actionName), $params);
}
$category->getController()
just returns it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question