ZF2 toRoute 与 https [英] ZF2 toRoute with https

查看:29
本文介绍了ZF2 toRoute 与 https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We're using Zend Framework 2 and use toRoute within our controllers to redirect to various locations, for example $this->redirect()->toRoute('home');.

无论如何,是否可以使用此方法或替代方法将此重定向到 https 而不是 http?

Is there anyway to have this redirect to https instead of http using this method or an alternative method?

谢谢!

推荐答案

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

In order to use https in your route you need to use the Zend\Mvc\Router\Http\Scheme router. Specifying the configuration for such route is not very different from the other routes. You need to specify the route type as Scheme and add an option 'scheme' => 'https' in your router configuration in 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'); 将工作.

If you have the route routename configured like above, this: $this->redirect()->toRoute('routename'); will work.

参见 this 参考 ZF2 的手册.

See this for reference to the ZF2's manual.

希望这有帮助:)

斯托扬

这篇关于ZF2 toRoute 与 https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆