![](/img/trans.png)
[英]Symfony CMF chain router: getting 404 error despite route matching
[英]Symfony CMF Dynamic router “was not able to match” logs
我有一個使用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)
{
}
}
如果有更好的方式來使用動態路線,我很想聽聽:)
日志條目在“調試”級別創建。 您可以設置更高的記錄器最低級別。 如果您需要調試日志來執行其他操作,則可以編寫CompilerPass來刪除symfony_cmf.router服務上的logger參數。
我同意可以配置日志級別,並使用false
選項完全禁用日志記錄是有意義的。 如果您願意,我很樂意在“路由”組件上查看並合並對代碼和“路由捆綁”的拉取請求,以公開配置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.