我们正在使用 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/