【问题标题】:Zend Framework 2 routing not working properly Windows 7Zend Framework 2 路由无法正常工作 Windows 7
【发布时间】:2015-11-25 22:09:56
【问题描述】:

我阅读了此处发布的所有问题,但找不到解决问题的方法。

我有 Windows 7、xampp、apache 2.4、php 5.6、zend 框架 2

我创建了一个名为 Application 的示例应用程序

这是我的 .htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

我的配置文件是这样的

   '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\Login' => 'Application\Controller\LoginController',
        'Application\Controller\Index' => 'Application\Controller\IndexController'
    ),
),

http://localhost:8080/lizziap/ 这个可行

localhost:8080/lizziap/Index 这不起作用

localhost:8080/lizziap/Login 这不起作用

localhost:8080/索引这不起作用

找不到页面。 请求的 URL 无法通过路由匹配。

没有可用的例外

我将非常感谢任何帮助...谢谢!

这就是配置现在的样子,并且可以正常工作

'router' => array(
    'routes' => array(
        'login' => array(
            'type' => 'segment',
            'options' => array(
                'route'    => '/login[/:action][/:id]',
                'constraints' => array(
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id'=>'[0-9a-zA-Z]*',
                ),
                'defaults' => array(
                    'controller' => 'Application\Controller\Login',
                    'action'     => 'login',

                ),
            ),
        ),
        'home' => array(
            'type' => 'Zend\Mvc\Router\Http\Literal',
            'options' => array(
                'route'    => '/',
                'defaults' => array(
                    'controller' => 'Application\Controller\Index',
                    'action'     => 'index',
                ),
            ),
        ),

【问题讨论】:

    标签: php zend-framework


    【解决方案1】:

    也许我的配置文件会对你有所帮助:

    return array(
    'controllers' => array(
        'invokables' => array(
            'Auth\Controller\Auth' => 'Auth\Controller\AuthController',
            'Auth\Controller\Success' => 'Auth\Controller\SuccessController',
        ),
    ),   
    'router' => array(
        'routes' => array(
            'auth' => array(
                'type' => 'segment',
                'options' => array(
                    'route'    => '/auth[/:action][/:id]', 
                    'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',  
                        'id'=>'[0-9a-zA-Z]*',                        
                    ),
                    'defaults' => array(
                        'controller' => 'Auth\Controller\Auth',
                        'action'     => 'index',
    
                    ),
                ),
            ),
            'success' => array(
                'type' => 'segment',
                'options' => array(
                    'route'    => '/success[/:action]', 
                    'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
    
                    ),
                    'defaults' => array(
                        'controller' => 'Auth\Controller\Success',
                        'action'     => 'index',
    
                    ),
                ),
            ),
        ),
    
    ),
    
    'view_manager' => array(
        'template_path_stack' => array(
            'auth' => __DIR__.'/../view',
        ),
    ),
    
    );
    

    【讨论】:

    • 谢谢,终于解决了……会更新原帖
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-26
    • 2014-12-05
    • 2018-01-17
    • 2017-10-15
    相关资源
    最近更新 更多