我们正在使用 Zend Framework 2 并使用toRoute
在我们的控制器中重定向到不同的位置,例如$this->redirect()->toRoute('home');
.
无论如何,是否可以使用此方法或替代方法将其重定向到 https 而不是 http?
谢谢你!
为了使用https
在你的路线中你需要使用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');
将工作。
See this http://framework.zend.com/manual/2.0/en/modules/zend.mvc.routing.html#zend-mvc-router-http-scheme参考ZF2的手册。
希望这可以帮助 :)
Stoyan
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)