【问题标题】:Symfony2 project - app_dev.php works but app.php has redirect loop on just specific pageSymfony2 项目 - app_dev.php 有效,但 app.php 仅在特定页面上有重定向循环
【发布时间】:2016-03-07 09:51:25
【问题描述】:

我不完全确定发生了什么,因为这是我第一次遇到这种问题,但由于某种原因,我的 Symfony2 项目中的一个特定页面在 app.php 上有一个重定向循环,但在 app_dev 上时.php,没关系。

页面名为/files,该页面的路由如下:

app_files_table:
    path: /files
    defaults: { _controller: AppBundle:File:list }

这个页面的控制器方法很简单:

public function listAction()
{
    $em = $this->getDoctrine()->getManager();
    $documents_repo = $em->getRepository('AppBundle:Documents');
    $documents = $documents_repo->findAll();

    return $this->render('AppBundle:tables:files.html.twig', array(
        'files' => $documents
    ));
}

twig 模板只是一个标准布局,它与我的所有其他页面(扩展我的作为标题的基本文件)在主体中使用以下代码匹配:

{% if files is not empty %}
{% for file in files %}
    <tr>
        <th scope="row">{{ file.id }}</th>
        <td>{{ file.name }}</td>
        <td>{{ file.displayName }}</td>
        <td>{{ file.product.model }}</td>
        <td class="text-center">
            <a class="btn btn-primary" href="{{ file_path }}/{{- file.name -}}" target="_blank" download><i class="fa fa-download"> </i></a>
            <a class="btn btn-danger file-delete" data-confirm-title="Are you sure?" data-confirm-message="You will not be able to undo this action." href="javascript:deleteFile({{ file.id }});" id="delete_file_{{ file.id }}" data-toggle="tooltip" title="Remove File"><i class="fa fa-remove"> </i></a>
        </td>
    </tr>
{% endfor %}
{% else %}
<tr>
<td colspan="5">There are no files in the database</td>
</tr>
{% endif %}

我没有编辑 app.php、app_dev.php 和 .htaccess 文件——它们与安装框架时一样。我还清除了两次缓存,包括手动删除所有缓存文件 - 但重定向问题仍然存在。

这是其他人遇到并设法解决的问题吗?因为我很困惑为什么它应该在这个页面上发生 - 事实上,我什至尝试在模板渲染之前在控制器中放置一个 die() 语句,但同样的事情发生了,所以它必须与路由有关?

任何帮助表示赞赏。

谢谢

编辑 - 调试结果:路由器

_wdt                                ANY        ANY      ANY    /_wdt/{token}
  _profiler_home                      ANY        ANY      ANY    /_profiler/
  _profiler_search                    ANY        ANY      ANY    /_profiler/search
  _profiler_search_bar                ANY        ANY      ANY    /_profiler/search_bar
  _profiler_purge                     ANY        ANY      ANY    /_profiler/purge
  _profiler_info                      ANY        ANY      ANY    /_profiler/info/{about}
  _profiler_phpinfo                   ANY        ANY      ANY    /_profiler/phpinfo
  _profiler_search_results            ANY        ANY      ANY    /_profiler/{token}/search/results
  _profiler                           ANY        ANY      ANY    /_profiler/{token}
  _profiler_router                    ANY        ANY      ANY    /_profiler/{token}/router
  _profiler_exception                 ANY        ANY      ANY    /_profiler/{token}/exception
  _profiler_exception_css             ANY        ANY      ANY    /_profiler/{token}/exception.css
  _twig_error_test                    ANY        ANY      ANY    /_error/{code}.{_format}
  app_dashboard                       ANY        ANY      ANY    /
  app_user_dashboard                  ANY        ANY      ANY    /user-dashboard
  fos_user_security_login             ANY        ANY      ANY    /login
  fos_user_security_check             ANY        ANY      ANY    /login_check
  app_customers_table                 ANY        ANY      ANY    /customers
  app_orders_table                    ANY        ANY      ANY    /orders
  app_projects_table                  ANY        ANY      ANY    /projects
  app_products_table                  ANY        ANY      ANY    /products
  app_files_table                     ANY        ANY      ANY    /documents
  app_users_table                     ANY        ANY      ANY    /users
  app_categories_table                ANY        ANY      ANY    /categories
  app_customer_view                   ANY        ANY      ANY    /customer/{id}/{orderYear}
  app_order_view                      ANY        ANY      ANY    /order/{id}
  app_project_view                    ANY        ANY      ANY    /project/{id}
  app_user_view                       ANY        ANY      ANY    /user/{id}
  app_customer_add                    ANY        ANY      ANY    /customer/add
  app_address_add                     ANY        ANY      ANY    /address/add/{id}
  app_order_add                       ANY        ANY      ANY    /order/add
  app_user_add                        ANY        ANY      ANY    /user/new
  app_stage_add                       ANY        ANY      ANY    /stage/new
  app_category_add                    ANY        ANY      ANY    /category/new
  app_document_add                    ANY        ANY      ANY    /document/new/
  fos_user_registration_register      ANY        ANY      ANY    /new-user
  fos_user_security_logout            ANY        ANY      ANY    /logout
  fos_user_registration_check_email   ANY        ANY      ANY    /check-email
  fos_user_registration_confirm       ANY        ANY      ANY    /confirm/{token}
  fos_user_registration_confirmed     ANY        ANY      ANY    /confirmed
  fos_user_profile_show               ANY        ANY      ANY    /profile
  fos_user_profile_edit               GET|POST   ANY      ANY    /profile-edit
  app_missing_orders_table            ANY        ANY      ANY    /missing-orders
  app_delete_item                     ANY        ANY      ANY    /delete/{type}/{id}
  app_calendar                        ANY        ANY      ANY    /calendar
  app_ajax_call                       ANY        ANY      ANY    /ajax-call/{action}/{data}
  app_customer_search                 ANY        ANY      ANY    /customer-search
  app_customer_get                    ANY        ANY      ANY    /customer-get
  app_product_search                  ANY        ANY      ANY    /product-search
  app_product_search_id               ANY        ANY      ANY    /product-search-by-id
  app_product_get                     ANY        ANY      ANY    /product-get
  app_add_order                       ANY        ANY      ANY    /add-order
  app_print_job_label                 ANY        ANY      ANY    /print-job-label/{id}
  app_claim_task                      ANY        ANY      ANY    /claim-task/{id}
  app_complete_task                   ANY        ANY      ANY    /complete-task/{id}
  app_stages_edit                     ANY        ANY      ANY    /edit-stages
  app_category_edit                   ANY        ANY      ANY    /edit-category/{id}
  app_run_cron_task                   ANY        ANY      ANY    /cron-generate-projects
  remove_trailing_slash               GET        ANY      ANY    /{url}
  fullcalendar_loader                 ANY        ANY      ANY    /fc-load-events
  fos_js_routing_js                   ANY        ANY      ANY    /js/routing.{_format}

【问题讨论】:

  • 你会被重定向到哪里?
  • 你在 prod.log 中有什么?
  • 它不会重定向到任何地方 - 我收到“页面未正确重定向”错误,就好像它试图找到正确的路线但只是来回走动。 Pawel - prod.log 中没有针对此错误的新日志。

标签: php symfony redirect


【解决方案1】:

我建议你重建你的引导缓存,你可以通过作曲家脚本来做,因为你可以做它的生产:

composer install -o --no-dev

或者干脆

composer run-script post-install-cmd

您也可以考虑删除整个缓存目录并删除app/bootstrap.php.cache 文件。

如果它不起作用,我们将需要更多信息,例如配置文件、环境、日志等。

【讨论】:

  • 我运行了该代码,然后在清除缓存后我得到:“致命错误:在 /Applications/XAMPP/xamppfiles/htdocs/eurotubes_crm/app/ 中找不到类 'Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle'第 31 行的 AppKernel.php" - 即使它在那里....加上重定向循环仍在发生。我可以在我的问题中包含更多信息,您到底需要什么?
  • 你能发布你的虚拟主机、环境变量和日志的最后几行吗?还要检查命令 debug:router 看看是否有什么奇怪的地方!但在我看来,您在某处有遗漏配置,因此您应该检查所有配置文件!
  • 调试信息没有显示任何异常 - 但我注意到在浏览器的网络面板中我得到状态“301 Moved Permanently”?环境变量只是 dev 和 prod。我在端口 8888 上使用 XAMPP,但它仍然在实时服务器上具有重定向循环。
  • 我最终将路由名称从“文件”更改为“文档”,这似乎解决了问题。也许它是 symfony 中的保留字/路由?或者它可能与我安装的包有关......
  • 它不是预定义的!你能显示 debug:router 的结果吗?
猜你喜欢
  • 1970-01-01
  • 2017-01-10
  • 2023-03-19
  • 2012-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-05
相关资源
最近更新 更多