簡體   English   中英

在zend 2 Framework應用程序中的請求URL上找不到頁面

[英]Page not found on request url in zend 2 framework application

我是zend框架的新手,我正在嘗試配置zend。 我在窗口7XAMPP上成功安裝了zendskeleton應用程序

安裝后,我將按照用戶指南中的定義創建新模塊相冊 我已經按照指南制作了所有代碼和頁面,但之后便可以打開Album模塊 我沒有找到錯誤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

您需要在瀏覽器中使用以下網址http://zf2-tutorial.localhost:8081/album而不是像您寫的http://zf2-tutorial.localhost/ZendSkeletonApplication/ZendSkeletonApplication-master/public/album

該網址指向內部的其他模塊/位置。

//編輯

如果這不起作用,請檢查您的zf2 /public文件夾是否存在.htaccess文件,否則請使用zend骨架應用程序中的文件https://github.com/zendframework/ZendSkeletonApplication/blob/master/public/.htaccess

如果port等於windows host文件端口,也請檢查您的apache vhost條目。

確保已加載Apache ModRewrite

您的設置中的基本錯誤配置會導致此錯誤。

  1. 我暫時不使用Windows,但是您在路徑中同時使用了正斜杠和反斜杠。 首先,您應該為Windows找到正確的目錄分隔符並堅持使用。 這似乎有問題: C:/xampp\\htdocs/foo/bar/public
  2. 您正在定義一個虛擬主機,該主機偵聽端口81 (*:81)上的任何IP地址,一個system32主機條目,該條目指向端口8081作為zf2-tutorial.localhost別名,並嘗試使用port調用zf2-tutorial.localhost/album url 80 得到這種錯誤很正常。

閱讀完官方的《 入門使用Apache Web Server 》官方文檔后,您將很容易找到解決方案。

看來您在Web服務器中缺少虛擬主機條目。 這可能是您的應用程序無法解決您的請求權限的原因。 再次檢查“入門:骨架應用程序”,以提供正確的配置。

您需要此主機文件條目。 在此文件中無法添加端口。

127.0.0.1 zf2-tutorial.localhost

該網站現在位於zf2-tutorial.localhost:81(而不是8081,您將httpd-vhosts.conf第一行中的端口號設置為81)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM