ZF2 toRoute with https

倾然丶 夕夏残阳落幕 提交于 2019-12-21 17:28:04

问题


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

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

Thank you!


回答1:


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.

Here is an example:

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
);

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

See this for reference to the ZF2's manual.

Hope this helps :)

Stoyan



来源:https://stackoverflow.com/questions/15797599/zf2-toroute-with-https

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!