doushaiyu5065
2015-11-25 22:09
浏览 44
已采纳

Zend Framework 2路由无法正常运行Windows 7

I read all the questions posted here and can´t find solution to my problem.

I have windows 7, xampp, apache 2.4, php 5.6, zend framework 2

I created a sample application named Application

This is my .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]

My config files looks like this

   '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/ this works

localhost:8080/lizziap/Index this doesnt works

localhost:8080/lizziap/Login this doesnt works

localhost:8080/Index this doesnt works

Page not found. The requested URL could not be matched by routing.

No Exception available

I will really appreciate any help ... THANKS!

This is how config looks now and it works

'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',
                ),
            ),
        ),
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douxuanpa8298 2015-11-25 22:37
    已采纳

    Maybe my config file will help you:

    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',
        ),
    ),
    
    );
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题