仅在一个页面中隐藏网址路径

时间:2015-07-03 19:55:56

标签: php apache .htaccess zend-framework zend-framework2

我有一个在Zend Framework 1和2中并行运行的项目(作为参考,我使用了本教程: Zf1 and Zf2 in parallel)。

在此项目中,在主屏幕中,此路径 - > http://network.school.com/ [此处使用的是ZF1]。

如果用户未被登录,他将被重定向到另一个屏幕,该屏幕使用库ZF2,如此路径 - > http://network.school.com/imr [此处我们正在使用ZF2库]。

重定向工作正常,每个项目的库不冲突。一切都好。 现在我遇到了一个问题:我需要只定制一个ZF2模块的网址,并根据具体情况,例如:

当用户在imr中时,应该从URL隐藏此地址/ imr。但是,/ imr具有子路由,当您访问子路由时,用户应该看到包含/ imr的路径。 像这样:

未经身份验证的用户或imr模块

http://network.school.com/但是用户应该看到/ imr模块,这是项目ZF2

如果用户已通过身份验证且已启用/,则应该看到ZF1索引,但网址仍然相同:

network.school.com/(即网址未更改)

访问imr的子路径

network.school.com/imr/media( 这里已经出现了包含孩子通常路线的模块名称,以及他们的行为)。

我怎么能做到这一点?

修改

这是我的modules.config.php(在zf2项目上。在zf1上找不到它。)

<?php
namespace Application;

/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

return array(
    'router' => array(
        'routes' => array(
            'home' => array(
                'type' => 'segment',
                'options' => array(
                    'route'    => '/',
                    'defaults' => array(
                        'controller' => 'Application\Controller\Index',
                        'action'     => 'index',
                    ),
                ),
            ),
            'imr' => array(
                'type'    => 'segment',
                'options' => array(
                    'route'    => '/imr[/][:action][/:id]',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller',
                        'controller'    => 'Index',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'media' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/media[/][:action][/:id]',
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                            ),
                            'defaults' => array(
                                'action'    =>  'media'
                            ),
                        ),
                    ),
                     'environment' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/environment[/][:action][/:id]',
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                            ),
                            'defaults' => array(
                                'action'    =>  'environment'
                            ),
                        ),
                    ),
                ),
            ),
            'Projetos' => array(
                'type'      => 'segment',
                'options' => array(
                    'route'         => '/Projetos[/][:action][/:id]',
                    'constraints'   => array(
                            'action'    => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'id'        => '[0-9]+',
                            ),
                    'defaults' => array(
                        'controller' => 'Application\Controller\Projetos',
                        'action'    => 'index',
                        ),
                ),
            ),

            'Ciclos' => array(
                'type'      => 'segment',
                'options' => array(
                    'route'         => '/Ciclos[/][:action][/:id]',
                    'constraints'   => array(
                            'action'    => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'id'        => '[0-9]+',
                            ),
                    'defaults' => array(
                        'controller' => 'Application\Controller\Ciclos',
                        'action'    => 'index',
                        ),
                ),                
            ),
            'MidiaTexto' => array(
                'type'      =>  'segment',
                'options'   => array(
                    'route'         => '/MidiaTexto[/][:action][/:id]',
                    'constraints'   => array(
                            'action'    => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'id'        => '[0-9]+',
                            ),
                    'defaults' => array(
                        'controller' => 'Application\Controller\MidiaTexto',
                        'action'    => 'index',
                        ),
                ),                
            ),
            'MidiaImagem' => array(
                'type'      =>  'segment',
                'options'   => array(
                    'route'         => '/MidiaImagem[/][:action][/:id]',
                    'constraints'   => array(
                            'action'    => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'id'        => '[0-9]+',
                            ),
                    'defaults' => array(
                        'controller' => 'Application\Controller\MidiaImagem',
                        'action'    => 'index',
                        ),
                ),                
            ),
             'ProjetosRE' => array(
                'type'      => 'segment',
                'options'   => array(
                    'route'         => '/ProjetosRE[/][:action][/:id]',
                    'constraints'   => array(
                            'action'    => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'id'        => '[0-9]+',
                            ),
                    'defaults' => array(
                        'controller' => 'Application\Controller\ProjetosRE',
                        'action'    => 'index',
                        ),
                ),                
            ),
            'UsuariosRE' => array(
                'type'      => 'segment',
                'options'   => array(
                    'route'         => '/UsuariosRE[/][:action][/:id]',
                    'constraints'   => array(
                            'action'    => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'id'        => '[0-9]+',
                            ),
                    'defaults' => array(
                        'controller' => 'Application\Controller\UsuariosRE',
                        'action'    => 'index',
                        ),
                ),                
            ),

            'test'  =>  array(
                'type'  =>  'segment',
                'options'   =>  array(
                    'route' =>  '/api/test[/:id]',
                    'defaults'  =>  array(
                        'controller'    => 'Application\Controller\Test',
                        ),
                    )),


        ),
    ),
    'service_manager' => array(
        'abstract_factories' => array(
            'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
            'Zend\Log\LoggerAbstractServiceFactory',
        ),
        'aliases' => array(
            'translator' => 'MvcTranslator',
        ),
    ),
    'translator' => array(
        'locale' => 'en_US',
        'translation_file_patterns' => array(
            array(
                'type'     => 'gettext',
                'base_dir' => __DIR__ . '/../language',
                'pattern'  => '%s.mo',
            ),
        ),
    ),
    'controllers' => array(
        'invokables' => array(
            'Application\Controller\Index'          => 'Application\Controller\IndexController',
            'Application\Controller\Projetos'       => 'Application\Controller\ProjetosController',
            'Application\Controller\Ciclos'         => 'Application\Controller\CiclosController',
            'Application\Controller\MidiaTexto'     => 'Application\Controller\MidiaTextoController',
            'Application\Controller\MidiaImagem'    => 'Application\Controller\MidiaImagemController',
            'Application\Controller\ProjetosRE'     => 'Application\Controller\ProjetosREController',
            'Application\Controller\UsuariosRE'     => 'Application\Controller\UsuariosREController',
            'Application\Controller\Test'           => 'Application\Controller\TestController'
        ),
    ),

    'view_manager' => array(
        'display_not_found_reason' => true,
        'display_exceptions'       => true,
        'doctype'                  => 'HTML5',
        'not_found_template'       => 'error/404',
        'exception_template'       => 'error/index',
        'template_map' => array(
            'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
            'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
            'error/404'               => __DIR__ . '/../view/error/404.phtml',
            'error/index'             => __DIR__ . '/../view/error/index.phtml',
        ),
        'template_path_stack' => array(
            __DIR__ . '/../view',
        ),
        'strategies' => array(
            'ViewJsonStrategy',
        ),

    ),

    'doctrine'     =>  array(
            'driver'    =>  array(
                __NAMESPACE__ .'_driver' =>  array(
                    'class' =>  'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
                    'cache' =>  'array',
                    'paths' =>  array(__DIR__.'/../src/'.__NAMESPACE__.'/Entity'),
                     ),
                'orm_default'   =>  array(
                    'drivers'   =>  array(__NAMESPACE__.'\Entity' =>  __NAMESPACE__.'_driver')
                    ),
                'orm_redeeducativa'   =>  array(
                    'drivers'   =>  array(__NAMESPACE__.'\Entity' =>  __NAMESPACE__.'_driver')
                    ),
                )
    ),
    // Placeholder for console routes
    'console' => array(
        'router' => array(
            'routes' => array(
            ),
        ),
    ),
);

0 个答案:

没有答案