2013-11-02 116 views
0

我試圖讓動態路由器正常工作。但是在我看來,它並沒有。 當我打電話「/web/app_dev.php/de/test」我得到Symfony2動態路由器不起作用

Stack Trace: [1] Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /de/test" 
    at n/a 
     in /var/www/myProject/app/cache/dev/classes.php line 1882 

    at Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(object(GetResponseEvent)) 
     in line 

    at call_user_func(array(object(RouterListener), 'onKernelRequest'), object(GetResponseEvent)) 
     in /var/www/myProject/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php line 450 

    at Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher->Symfony\Component\HttpKernel\Debug\{closure}(object(GetResponseEvent)) 
     in line 

    at call_user_func(object(Closure), object(GetResponseEvent)) 
     in /var/www/myProject/app/cache/dev/classes.php line 1666 

    at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure)), 'kernel.request', object(GetResponseEvent)) 
     in /var/www/myProject/app/cache/dev/classes.php line 1599 

    at Symfony\Component\EventDispatcher\EventDispatcher->dispatch('kernel.request', object(GetResponseEvent)) 
     in /var/www/myProject/app/cache/dev/classes.php line 1763 

    at Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.request', object(GetResponseEvent)) 
     in /var/www/myProject/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php line 139 

    at Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher->dispatch('kernel.request', object(GetResponseEvent)) 
     in /var/www/myProject/app/bootstrap.php.cache line 2804 

    at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1') 
     in /var/www/myProject/app/bootstrap.php.cache line 2789 

    at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true) 
     in /var/www/myProject/app/bootstrap.php.cache line 2918 

    at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true) 
     in /var/www/myProject/app/bootstrap.php.cache line 2220 

    at Symfony\Component\HttpKernel\Kernel->handle(object(Request)) 
     in /var/www/myProject/web/app_dev.php line 29 

[2] Symfony\Component\Routing\Exception\ResourceNotFoundException: None of the routers in the chain matched this request GET /myProject/web/app_dev.php/de/test HTTP/1.1 Accept:   text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding: gzip, deflate Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3 Cache-Control: no-cache Connection:  keep-alive Cookie:   PHPSESSID=6a5ds9lfehu405ai79o7tm1h55; lunetics_locale=de Host:   localhost Pragma:   no-cache User-Agent:  Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0 X-Php-Ob-Level: 1 


    at n/a 
     in /var/www/myProject/vendor/symfony-cmf/routing/Symfony/Cmf/Component/Routing/ChainRouter.php line 192 

    at Symfony\Cmf\Component\Routing\ChainRouter->doMatch('/de/test', object(Request)) 
     in /var/www/myProject/vendor/symfony-cmf/routing/Symfony/Cmf/Component/Routing/ChainRouter.php line 147 

    at Symfony\Cmf\Component\Routing\ChainRouter->matchRequest(object(Request)) 
     in /var/www/myProject/app/cache/dev/classes.php line 1869 

    at Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(object(GetResponseEvent)) 
     in line 

    at call_user_func(array(object(RouterListener), 'onKernelRequest'), object(GetResponseEvent)) 
     in /var/www/myProject/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php line 450 

    at Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher->Symfony\Component\HttpKernel\Debug\{closure}(object(GetResponseEvent)) 
     in line 

    at call_user_func(object(Closure), object(GetResponseEvent)) 
     in /var/www/myProject/app/cache/dev/classes.php line 1666 

    at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure)), 'kernel.request', object(GetResponseEvent)) 
     in /var/www/myProject/app/cache/dev/classes.php line 1599 

    at Symfony\Component\EventDispatcher\EventDispatcher->dispatch('kernel.request', object(GetResponseEvent)) 
     in /var/www/myProject/app/cache/dev/classes.php line 1763 

    at Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.request', object(GetResponseEvent)) 
     in /var/www/myProject/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php line 139 

    at Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher->dispatch('kernel.request', object(GetResponseEvent)) 
     in /var/www/myProject/app/bootstrap.php.cache line 2804 

    at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1') 
     in /var/www/myProject/app/bootstrap.php.cache line 2789 

    at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true) 
     in /var/www/myProject/app/bootstrap.php.cache line 2918 

    at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true) 
     in /var/www/myProject/app/bootstrap.php.cache line 2220 

    at Symfony\Component\HttpKernel\Kernel->handle(object(Request)) 
     in /var/www/myProject/web/app_dev.php line 29 

也是我的Symfony分析器告訴我,有沒有發送到數據庫中的任何查詢。這就是爲什麼我假設動態路由器沒有檢查phpcr-nodes。

這是我的配置文件的文檔片斷:

# CMF Routing 
cmf_routing: 
    chain: 
     routers_by_id: 
      cmf_routing.dynamic_router: 200 
      router.default: 100 
    dynamic: 
     controllers_by_class: 
      Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\RedirectRoute: cmf_routing.redirect_controller:redirectAction 
     persistence: 
      phpcr: 
       enabled: true 
       use_sonata_admin: true 

       content_basepath:/
       route_basepath:/
     locales: 
      - de 
      - en 



cmf_core: 
    persistence: 
     phpcr: 
      enabled: true 
      basepath:/


cmf_block: 
    persistence: 
     phpcr: 
      enabled: true 
      manager_name: default 
      use_sonata_admin: true 
      content_basepath:/
    use_imagine: false 

cmf_content: 
    persistence: 
     phpcr: 
      content_basepath: /content 

# Doctrine Configuration 
doctrine: 
    dbal: 
     driver: %database_driver% 
     host:  %database_host% 
     port:  %database_port% 
     dbname: %database_name% 
     user:  %database_user% 
     password: %database_password% 
     charset: UTF8 
     types: 
      json: Sonata\Doctrine\Types\JsonType 

    orm: 
     auto_generate_proxy_classes: %kernel.debug% 
     auto_mapping: true 


# PHPCR 
doctrine_phpcr: 
    session: 
     backend: 
      type: doctrinedbal 
      #connection: default 
     workspace: default 
     username: admin 
     password: admin 
    odm: 
     document_managers: 
      default: 
       auto_mapping: true 
       session: default 
       mappings: 
        CmfContentBundle: ~ 
        CmfMenuBundle: ~ 
        CmfRoutingBundle: ~ 
     auto_generate_proxy_classes: %kernel.debug% 
     proxy_dir:   %kernel.cache_dir%/doctrine/PHPCRProxies 
     proxy_namespace:  PHPCRProxies 
     locales: 
      de: [en] 
      en: [de] 

sonata_doctrine_phpcr_admin: 
    document_tree_defaults: [locale] 
    document_tree: 
     Doctrine\ODM\PHPCR\Document\Generic: 
      valid_children: 
       - all 
     Symfony\Cmf\Bundle\SimpleCmsBundle\Document\Page: ~ 
     Symfony\Cmf\Bundle\RoutingBundle\Document\Route: 
      valid_children: 
       - Symfony\Cmf\Bundle\RoutingBundle\Document\Route 
       - Symfony\Cmf\Bundle\RoutingBundle\Document\RedirectRoute 
     Symfony\Cmf\Bundle\RoutingBundle\Document\RedirectRoute: 
      valid_children: [] 
     Symfony\Cmf\Bundle\MenuBundle\Document\MenuNode: 
      valid_children: 
       - Symfony\Cmf\Bundle\MenuBundle\Document\MenuNode 
       - Symfony\Cmf\Bundle\MenuBundle\Document\MultilangMenuNode 
     Symfony\Cmf\Bundle\ContentBundle\Doctrine\Phpcr\StaticContent: 
      valid_children: 
       - all 
     Symfony\Cmf\Bundle\MenuBundle\Document\MultilangMenuNode: 
      valid_children: 
       - Symfony\Cmf\Bundle\MenuBundle\Document\MenuNode 
       - Symfony\Cmf\Bundle\MenuBundle\Document\MultilangMenuNode 

我使用索納塔管理和配置的後端內/德/測試路線。這是生成的數據庫條目:

| id | path  | parent | local_name | namespace | workspace_name | identifier       | type   | props                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | depth | sort_order | 
| 21 | /de/test | /de | test  |   | default  | 24ec587c-b6f0-4a3f-af23-e107b0a21a32 | nt:unstructured | <?xml version="1.0" encoding="UTF-8"?><sv:node xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:rep="internal"><sv:property sv:name="jcr:primaryType" sv:type="Name" sv:multi-valued="0"><sv:value>nt:unstructured</sv:value></sv:property><sv:property sv:name="jcr:mixinTypes" sv:type="Name" sv:multi-valued="1"><sv:value>phpcr:managed</sv:value><sv:value>mix:referenceable</sv:value></sv:property><sv:property sv:name="phpcr:class" sv:type="String" sv:multi-valued="0"><sv:value>Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route</sv:value></sv:property><sv:property sv:name="phpcr:classparents" sv:type="String" sv:multi-valued="1"><sv:value>Symfony\Component\Routing\Route</sv:value><sv:value>Symfony\Cmf\Bundle\RoutingBundle\Model\Route</sv:value></sv:property><sv:property sv:name="jcr:uuid" sv:type="String" sv:multi-valued="0"><sv:value>24ec587c-b6f0-4a3f-af23-e107b0a21a32</sv:value></sv:property><sv:property sv:name="host" sv:type="String" sv:multi-valued="0"><sv:value></sv:value></sv:property><sv:property sv:name="defaultsKeys" sv:type="String" sv:multi-valued="1"><sv:value>_controller</sv:value></sv:property><sv:property sv:name="defaults" sv:type="String" sv:multi-valued="1"><sv:value>ASVDefaultBundle:Default:index</sv:value></sv:property><sv:property sv:name="requirements" sv:type="String" sv:multi-valued="1"/><sv:property sv:name="options" sv:type="String" sv:multi-valued="1"/><sv:property sv:name="addFormatPattern" sv:type="Boolean" sv:multi-valued="0"><sv:value>0</sv:value></sv:property><sv:property sv:name="addTrailingSlash" sv:type="Boolean" sv:multi-valued="0"><sv:value>0</sv:value></sv:property></sv:node> |  2 |   2 | 

這是我作曲的要求:

"require" : { 
     "doctrine/doctrine-fixtures-bundle" : "dev-master", 
     "jackalope/jackalope-doctrine-dbal" : "dev-master", 
     "friendsofsymfony/user-bundle" : "*", 
     "symfony/swiftmailer-bundle" : "2.3.*", 
     "sonata-project/cache-bundle" : "dev-master", 
     "doctrine/orm" : ">=2.2.3,<2.4-dev", 
     "sonata-project/user-bundle" : "dev-master", 
     "lunetics/locale-bundle" : "dev-master", 
     "twig/extensions" : "1.0.*", 
     "php" : ">=5.3.3", 
     "symfony-cmf/symfony-cmf" : "dev-master", 
     "symfony/monolog-bundle" : "2.3.*", 
     "sensio/distribution-bundle" : "2.3.*", 
     "symfony/symfony" : "2.3.*", 
     "doctrine/phpcr-bundle" : "1.0.0-beta4", 
     "sonata-project/doctrine-orm-admin-bundle" : "2.*", 
     "sonata-project/easy-extends-bundle" : "dev-master", 
     "doctrine/phpcr-odm" : "1.0.0-beta5", 
     "symfony/assetic-bundle" : "2.3.*", 
     "incenteev/composer-parameter-handler" : "~2.0", 
     "sonata-project/doctrine-phpcr-admin-bundle" : "dev-master", 
     "sonata-project/intl-bundle" : "dev-master", 
     "sensio/generator-bundle" : "2.3.*", 
     "sensio/framework-extra-bundle" : "2.3.*", 
     "doctrine/doctrine-bundle" : "1.2.*" 
    } 

有誰知道這個問題可能是什麼?

回答

0

我想通了。 我在這裏有兩個問題。

首先,我必須配置cmf_routing.routes_basepath以獲取節點的正確前綴。我試圖強制它成爲根節點/。但是,當我這樣做時,甚至沒有數據庫查詢了。事實證明,這種失誤來自我配置的routes_basepath。除/之外的任何其他值都會在頁面載入中引起查找。

所以我不得不創建一個新的節點(如該文件建議「中的「/路線」),以及cmf_routing.routes_basepath設置爲節點名稱。

現在它工作正常(只要路由在路由節點下創建。

+0

你能提供關於這方面的更多細節嗎?我嘗試添加 routes_basepath:下cmf_routing/CMS /路由 : 但收到以下錯誤消息:下 [Symfony的\元器件\配置\定義\異常\ InvalidConfigurationException] 無法識別的選項 「routes_basepath」「 cmf_routing「 – AlexG

+2

執行'.app/console config:dump-reference cmf_routing',你會看到放置routes_basepath的位置。 – enigma

0

對不起,不回答原來的問題

你似乎缺少的配置,使一般的動態路由器。

cmf_routing: 
    dynamic: 
     enabled: true 

參見在http://symfony.com/doc/master/cmf/bundles/routing/dynamic.html

我同意,如果它被指定任何配置的bundle應該激活動態路由器的文檔 - 如果你想要做一個拉要求提高,你是歡迎。 (這已經是這種情況)

+0

不幸的是,這也不起作用。根據您在答案中發佈的同一網址下的文檔,您建議的內容應該已經實施。 「只要將任何其他配置添加到動態條目,路由器就會自動啓用。」 – enigma

+0

@dbu這確實已經實現了:https://github.com/symfony-cmf/RoutingBundle/blob/master/DependencyInjection/Configuration.php#L57 –

+0

@WouterJ所以這是canBeEnabled的語義?只要周圍的任何東西都配置好了,它就是真的嗎?不錯。 – dbu

0

再次讀這個問題,我真的懷疑事情是否混合起來。數據庫中的示例看起來像Doctrine ORM。但是你啓用了Doctrine phpcr-odm加載。你可能是想要啓用orm嗎?然後,您需要查看配置的persistence.orm部分。

但是,應該更容易一些(特別是如果你想使用CMF的其他部分,而不建立自己的模型)是使用PHPCR-ODM的路線。除非您配置不同,否則路由位於/ cms/routes中的存儲庫中。 PHPCR-ODM路線文件在這裏http://symfony.com/doc/master/cmf/bundles/routing/dynamic.html