php - ZF2 toRoute 与 https

标签 php zend-framework2

我们正在使用 Zend Framework 2 并在我们的 Controller 中使用 toRoute 来重定向到不同的位置,例如 $this->redirect()->toRoute('home');

是否有使用此方法或替代方法将此重定向到 https 而不是 http?

谢谢!

最佳答案

为了使用https在您的 route ,您需要使用 Zend\Mvc\Router\Http\Scheme路由器。为此类路由指定配置与其他路由没有太大区别。您需要将路由类型指定为 Scheme并添加一个选项 'scheme' => 'https'在 module.config.php 中的路由器配置中。

这是一个例子:

return array(
    'router' => array(
        'routes' => array(
            'routename' => array(
                'type' => 'Scheme', // <- This is important
                'options' => array(
                    'route' => '/url',
                    'scheme' => 'https', // <- and this.
                    'defaults' => array(
                        '__NAMESPACE__' => 'MdlNamespace\Controller',
                        'controller' => 'Index',
                        'action' => 'someAction',
                    ),
                ),
            ),
            // the rest of the routes
        ),
    ),
    // the rest of the module config
);

如果你有路线routename配置如上,这个:$this->redirect()->toRoute('routename');将工作。

参见 this以供引用 ZF2 的手册。

希望这有帮助:)

斯托扬

关于php - ZF2 toRoute 与 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15797599/

相关文章:

linux - Xampp 无法在 Linux 上运行

php - ZF2 - 使用导航 View 助手的多个导航菜单

php - 将文件 uploader 添加到 Joomla 管理组件

php - MySQL 插入在一次提交中发生两次

php - 在 PHP 中将 HTML 转换为纯文本以用于电子邮件

php - Wordpress:你不能编辑这篇文章(即使我是管理员)

PHP ZF2 Mysql 已经消失

php - ZF2 中同一模块下的多个 namespace

php - 删除重复条目

php - ZF2 - 验证失败时不在输入元素下显示 zend 验证程序消息