我有一个使用 Symfony CMF 路由包 1.3 的 Symfony 2.6 应用程序,我们将普通 symfony 路由和动态路由组合用于自定义存储(除其他外,下面的示例重点关注我们的动态路由器之一)。
问题是我们收到了关于路由器无法匹配动态路由的无休止的日志,当它们正常工作时。
最常见的条目是:
Router Symfony\Bundle\FrameworkBundle\Routing\Router was not able to match, message ""
我们偶尔会看到
Router Symfony\Cmf\Bundle\RoutingBundle\Routing\DynamicRouter was not able to match, message ""
有没有办法禁用这些日志或更改我的动态路由器配置/设置,以便这些错误仅在路由实际失败时出现。
这是我的配置/设置:
# app/config/config.yml
cmf_routing:
chain:
routers_by_id:
router.default: 32
cmf_routing.dynamic_router: 30
dynamic:
enabled: true
route_provider_service_id: store_router
而实际的动态路由器基于
// StoreBundle/Router/StoreRouter.php
<?php
/**
* @DI\Service("store_router")
*/
class StoreRouter implements RouteProviderInterface
{
protected $em;
/**
* @DI\InjectParams({
* "em" = @DI\Inject("doctrine.orm.entity_manager")
* })
*/
public function __construct(EntityManager $em)
{
$this->em = $em;
}
/**
* @param Request $request
* @return RouteCollection
*/
public function getRouteCollectionForRequest(Request $request)
{
$collection = new RouteCollection();
$store = $this->em->getRepository('StoreBundle:Store')->findOneBySlug(substr($request->getPathInfo(), 1), $request->get('key', null));
// no store found, return an empty collection
if (empty($store)) {
return $collection;
}
$route = new Route(
'/' . $store->getSlug(),
[
'_controller' => 'StoreBundle:Store:view',
'slug' => $stote->getSlug()
]
);
$collection->add($store->getSlug(), $route);
return $collection;
}
public function getRouteByName($name, $params = [])
{
}
public function getRoutesByNames($names)
{
}
}
如果有更好的方法来使用动态路由,我很乐意听到它:)