【问题标题】:Symfony CMF Dynamic router "was not able to match" logsSymfony CMF 动态路由器“无法匹配”日志
【发布时间】:2016-01-16 19:40:24
【问题描述】:

我有一个使用 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)
    {
    }
}

如果有更好的方法来使用动态路线,我很乐意听到它:)

【问题讨论】:

    标签: php symfony symfony-cmf symfony-routing


    【解决方案1】:

    日志条目是在“调试”级别创建的。您可以将记录器的最低级别设置得更高。如果你需要调试日志来做其他事情,你可以编写一个 CompilerPass 来移除 symfony_cmf.router 服务上的 logger 参数。

    我同意配置日志级别是有意义的,使用false 选项可以完全禁用日志记录。如果你想要这个,我很高兴审查并合并 Routing 组件上的代码和 RoutingBundle 的拉取请求以公开配置。

    【讨论】:

    • 我不知道如何将其设置为调试。现在踢自己!谢谢
    • 别踢,如果有帮助很高兴
    猜你喜欢
    • 1970-01-01
    • 2016-02-07
    • 1970-01-01
    • 2019-03-21
    • 1970-01-01
    • 1970-01-01
    • 2014-10-03
    • 1970-01-01
    • 2014-03-16
    相关资源
    最近更新 更多