2014-11-04 89 views
0

我在symfony中開發了一個非常簡單的博客。 有2個捆綁包:博客和管理員在開發環境中都很好..但是主要管理路線似乎不能在prod中工作,因爲它會拋出404。每個其他路線(例如/ admin/categories等)都可以使用,但/ admin只有在寫入/app_dev.php/admin時纔有效。已經清除緩存。 我不認爲我插入了一些代碼來阻止管理員因爲我不知道我在哪裏可以做這樣的事情.. 也不知道究竟代碼片段需要調試抱歉,但我會更新如果有人要求一個。Symfony 2路由不能在產品中工作

管理員路線:

admin_image_upload: 
    path:  /imageupload 
    defaults: { _controller: SzoBeszAdminBundle:Admin:imageUpload } 

admin_posts: 
    path:  /admin 
    defaults: { _controller: SzoBeszAdminBundle:Admin:index } 

admin_posts_paginated: 
    path:  /admin/posts/{pageNumber} 
    defaults: { _controller: SzoBeszAdminBundle:Admin:index } 

admin_categories: 
    path:  /admin/categories 
    defaults: { _controller: SzoBeszAdminBundle:Admin:category } 

admin_category_submit: 
    path:  /admin/categorysubmit 
    defaults: { _controller: SzoBeszAdminBundle:Admin:categorySubmit } 

admin_post_submit: 
    path: /admin/postsubmit 
    defaults: { _controller: SzoBeszAdminBundle:Admin:postSubmit } 
    requirements: 
     _method: GET|POST 

admin_post_edit: 
    path: /admin/post/edit/{id} 
    defaults: { _controller: SzoBeszAdminBundle:Admin:postEdit } 
    requirements: 
     id: \d+ 

admin_post_delete: 
    path: /admin/post/delete/{id} 
    defaults: { _controller: SzoBeszAdminBundle:Admin:postDelete } 
    requirements: 
     id: \d+ 

admin_category_edit: 
    path: /admin/category/edit/{id} 
    defaults: { _controller: SzoBeszAdminBundle:Admin:categoryEdit } 
    requirements: 
     id: \d+ 

admin_category_delete: 
    path: /admin/category/delete/{id} 
    defaults: { _controller: SzoBeszAdminBundle:Admin:categoryDelete } 
    requirements: 
     id: \d+ 

博客路線:

blog_homepage: 
    path: /
    defaults: { _controller: BlogBundle:Main:index } 
    requirements: 
     _method: GET 

blog_homepaginated: 
    path:  /page/{pageNumber} 
    defaults: { _controller: BlogBundle:Main:index } 

blog_categorypage: 
    path:  /{theCategory} 
    defaults: { _controller: BlogBundle:Main:showCategory } 
    requirements: 
     _method: GET 

blog_categorypaginated: 
    path:  /{theCategory}/page/{pageNumber} 
    defaults: { _controller: BlogBundle:Main:showCategory } 
    requirements: 
     _method: GET 

blog_tagpage: 
    path:  /tag/{tag} 
    defaults: { _controller: BlogBundle:Main:tag } 

blog_showpost: 
    path:  /{theCategory}/{title} 
    defaults: { _controller: BlogBundle:Main:showPost } 
    requirements: 
     _method: GET 

blog_tagpaginated: 
    path:  /tag/{tag}/page/{pageNumber} 
    defaults: { _controller: BlogBundle:Main:tag } 

安全:

security: 
    encoders: 
     Symfony\Component\Security\Core\User\User: plaintext 

    role_hierarchy: 
     ROLE_ADMIN:  ROLE_USER 
     ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] 

    providers: 
     in_memory: 
      memory: 
       users: 
        szobeszadmin: { password: ***, roles: [ 'ROLE_SUPER_ADMIN' ] } 

    firewalls: 
     dev: 
      pattern: ^/(_(profiler|wdt)|css|images|js)/ 
      security: false 

     admin_secured: 
      pattern: ^/ 
      anonymous: ~ 
      http_basic: 
       realm: "Secured Area"  

    access_control:  
     - { path: ^/admin, roles: ROLE_SUPER_ADMIN } 
+0

比較'router:debug --env = prod'和'router:debug --env = dev' – Koalabaerchen 2014-11-04 22:21:26

+0

您是否試過在部署服務器上或/web/.htaccess中查看重寫規則? – Stan 2014-11-05 06:06:23

+0

比較但沒有和是規則是好的 – fagyi 2014-11-05 17:36:34

回答

1

確保註冊您的所有您所創建的BUNDLES在內核都在這裏,這是一個刺部分:

$bundles = array(...); 

休假註冊開發包是這樣的:

if (in_array($this->getEnvironment(), array('dev', 'test'))) { 
    $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); 
    $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle(); 
    $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle(); 
} 

此外,如果在app.php文件,你看到假的(參數是用於測試):

$kernel = new AppKernel('prod', false); 

false改爲true:

$kernel = new AppKernel('prod', true); 

希望它有幫助,祝你有美好的一天。

+0

不,這些在我的代碼是正確的:/但thx的答覆 – fagyi 2014-11-05 17:01:47

0

確保您在Apache中啓用了mod_rewrite模塊。

請參閱here尋求幫助。

0

問題是我在web文件夾內創建了一個admin文件夾,所以apache嘗試使用該文件夾的/ admin路由而不是我設置的路由。