在zend 2框架应用程序中的请求URL上找不到页面 [英] Page not found on request url in zend 2 framework application

查看:100
本文介绍了在zend 2框架应用程序中的请求URL上找不到页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是zend框架的新手,并且正在尝试配置zend.我已在第7窗口 XAMPP

上成功安装了zendskeleton应用程序

安装后,按照用户指南中的定义创建新模块相册.我已经按照指南制作了所有代码和页面,但之后便可以打开相册模块.我没有找到错误404.

此处代码

  1. application.config

     return array(
    
     'modules' => array(
     'Application','Album',
     ),
    
    'module_paths' => array(
    './module',
    './vendor',
    ),
    
    'config_glob_paths' => array(
    'config/autoload/{,*.}{global,local}.php',
     ),
    
      ),
        );
    

  2. module.config

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

  3. Module.php

    namespace Album;
    
     // Add these import statements:
     use Album\Model\Album;
     use Album\Model\AlbumTable;
     use Zend\Db\ResultSet\ResultSet;
     use Zend\Db\TableGateway\TableGateway;
    
     class Module
     {
      // getAutoloaderConfig() and getConfig() methods here
    
    
    
     // Add this method:
      public function getServiceConfig()
       {
          return array(
          'factories' => array(
          'Album\Model\AlbumTable' => function($sm) {
           $tableGateway = $sm->get('AlbumTableGateway');
           $table = new AlbumTable($tableGateway);
           return $table;
       },
         'AlbumTableGateway' => function ($sm) {
          $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
          $resultSetPrototype = new ResultSet();
          $resultSetPrototype->setArrayObjectPrototype(new Album());
          return new TableGateway('album', $dbAdapter, null, $resultSetPrototype);
        },
       ),
       );
       }
        }
    

  4. httpd-vhosts.conf

     <VirtualHost *:81>
     ServerName zf2-tutorial.localhost
     DocumentRoot "C:/xampp\htdocs/ZendSkeletonApplication/ZendSkeletonApplication-master/public"
     SetEnv APPLICATION_ENV "development"
     <Directory C:/xampp\htdocs/ZendSkeletonApplication/ZendSkeletonApplication-master/public>
      DirectoryIndex index.php
      AllowOverride All
      Order allow,deny
      Allow from all
      </Directory>
      </VirtualHost>
    

  5. system32

    上的主机条目

      127.0.0.1:8081       zf2-tutorial.localhost
    

我该如何处理. 谢谢

当您将apache文档根指向C:/xampp\htdocs/ZendSkeletonApplication/ZendSkeletonApplication-master/public

时,

解决方案

您需要在浏览器中使用此URL http://zf2-tutorial.localhost:8081/album 而不像你写的http://zf2-tutorial.localhost/ZendSkeletonApplication/ZendSkeletonApplication-master/public/album

此网址指向内部的其他模块/位置.

//编辑

如果这不起作用,请检查zf2 /public文件夹中是否存在.htaccess文件,否则请使用zend骨架应用程序中的文件

  • host entry at system32

      127.0.0.1:8081       zf2-tutorial.localhost
    

  • How can i handle it. Thanks

    解决方案

    when you point with your apache document root to C:/xampp\htdocs/ZendSkeletonApplication/ZendSkeletonApplication-master/public

    you need to use in your browser this url http://zf2-tutorial.localhost:8081/album and not like you wrote http://zf2-tutorial.localhost/ZendSkeletonApplication/ZendSkeletonApplication-master/public/album

    this url points internal to a different module/location.

    //edit

    if this not work check your zf2 /public folder if there is a .htaccess file present otherwise use the file from the zend skeleton application here https://github.com/zendframework/ZendSkeletonApplication/blob/master/public/.htaccess

    please check also your apache vhost entry if the port is equal to your windows host file port.

    make sure apache ModRewrite is loaded!

    这篇关于在zend 2框架应用程序中的请求URL上找不到页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆