1

我在使用 zend 框架创建模块化应用程序时遇到问题,我多次学习了更多教程和模块,但我总是遇到同样的错误。

我的应用程序的结构如下图所示。

+网站

  • 应用

    +配置

    +模块

      admin
    
      default
    

    +引导程序.php

  • 文档

  • 图书馆

  • 上市

  • 测试

在每个模块中,我都有一个扩展类 Zend_Application_Module_Bootstrap 的类,分别是:

  • Admin_Bootstrap
  • Default_Bootstrap

我的 application.ini 文件如下:

[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0

;module support
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] = ""
resources.frontController.params.prefixDefaultModule = "1"
resources.frontController.defaultModule="default"
;end module support
[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

如果我尝试访问该 urlhttp://localhost/site.it/public/没关系,但如果我尝试访问该 urlhttp://localhost/site.it/public/admin 我收到错误 The requested URL http://localhost/site.it/public/adminwas not found on this server.

文件 .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]

怎么了?

4

1 回答 1

0

你最好使用像 siteit.localhost 这样的别名,这样你就不需要每次都写 public 。这可能会解决您的问题,但我需要添加一些东西;在模块 admin 中,控制器的名称前是否有 Admin?

喜欢

class Admin_IndexController extends Zend_Controller_Action {...

顺便说一句,在我们的代码中,我们像这样在模块中包含每个文件夹,(如果您不使用子视图,请删除子视图行)

define('ROOT_DIR', realpath(dirname(__FILE__) . '/../'));

$modules = array('admin', 'foo' , 'asdasd');

foreach ($modules as $module) {
    set_include_path(get_include_path() . PATH_SEPARATOR . ROOT_DIR . '/application/modules/' . $module . '/models');
    set_include_path(get_include_path() . PATH_SEPARATOR . ROOT_DIR . '/application/modules/' . $module . '/forms');
    set_include_path(get_include_path() . PATH_SEPARATOR . ROOT_DIR . '/application/modules/' . $module . '/views');
    set_include_path(get_include_path() . PATH_SEPARATOR . ROOT_DIR . '/application/modules/' . $module . '/controllers');
    $subview->addBasePath(get_include_path() . PATH_SEPARATOR . ROOT_DIR . '/application/modules/' . $module . '/views');
}
于 2013-02-11T21:43:31.697 回答