【问题标题】:How to format URL in _redirect call如何在 _redirect 调用中格式化 URL
【发布时间】:2013-06-04 19:17:06
【问题描述】:

我的项目文件夹是 demo,里面有文件夹 application、library 和 public。我的 index.php 在公用文件夹中。因此,我将浏览器指向 localhost/demo/public。在我的应用程序文件夹中,我有一个控制器文件夹,里面有我的 IndexController。在这个索引控制器中,我的 indexAction 方法是:

   $this->_redirect('/auth/login');
   $this->_helper->layout->disableLayout();
   $this->_helper->viewRenderer->setNoRender(true);

因此,在此方法中,我想重定向到位于同一控制器目录中的 AuthController 到其操作登录。但浏览器呈现:

在此服务器上找不到请求的 URL /demo/public/auth/login。

AuthController 在控制器中,而不是在公共文件夹中。如何在我的 _redirect 调用中正确格式化 URL 字符串?

【问题讨论】:

    标签: zend-framework


    【解决方案1】:

    使用重定向器操作助手

    $this->_helper->redirector('auth','login');
    

    【讨论】:

      【解决方案2】:

      尝试使用 url view helper,例如:

      $this->_redirect($this->view->url(array('controller'=>'auth','action'=>'login');
      

      另一种选择是尝试绝对格式化您的 URL,例如:

      $this->_redirect($_SERVER['HTTP_ROOT'].'/auth/login')
      

      虽然第一个选项应该更安全。

      【讨论】:

        猜你喜欢
        • 2021-08-17
        • 1970-01-01
        • 2017-08-01
        • 2016-11-27
        • 1970-01-01
        • 1970-01-01
        • 2016-03-10
        • 2018-04-02
        • 1970-01-01
        相关资源
        最近更新 更多