1

我一直在尝试编写一个基本的身份验证系统,作为我应该使用的项目的一部分,以了解 Zend 框架。我一直在使用 Zend CLI 工具来帮助创建我的应用程序。我有一个名为 Admin 的模块,其中有一个名为 Auth 的控制器。但是,当我尝试在浏览器中导航到控制器时,出现以下错误:

An error occurred

Page not found

Exception information:

Message: Invalid controller specified (auth)

Stack trace:

#0 /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#1 /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#2 /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#3 /home/www-data/zend.danielgroves.net/htdocs/public/index.php(26): Zend_Application->run()
#4 {main}  
Request Parameters:

array (
  'module' => 'admin',
  'controller' => 'auth',
  'action' => 'index',
)

您可以前往 zend.danielgroves.net 亲自查看

据我所知,所有内容均已正确命名,请查看下面的屏幕截图,了解 CLI 工具如何构建所有内容。这是我在尝试构建此登录系统时遵循的指南http://akrabat.com/zend-auth-tutorial/。我刚刚到达登录屏幕截图的部分(第一张图片)。

Zend 目录/文件结构

任何帮助将不胜感激。

编辑 1

我的 application.ini 文件发布了@ByteNudger 建议的更改:

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
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

resources.db.adapter = "Pdo_Mysql"
resources.db.params.charset = "utf8"
resources.db.params.host = "localhost"
resources.db.params.username = ""
resources.db.params.password = ""
resources.db.params.dbname = ""

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"

resources.modules[] = "" (section [bootstrap])

[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

application.ini 生成的 PHP 错误更改:

PHP Fatal error:  Uncaught exception 'Zend_Config_Exception' with message 'syntax error, unexpected '(' in /home/www-data/zend.danielgroves.net/htdocs/application/configs/application.ini on line 20' in /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Config/Ini.php:182
Stack trace:
#0 /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Config/Ini.php(202): Zend_Config_Ini->_parseIniFile('/home/www-data/...')
#1 /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Config/Ini.php(126): Zend_Config_Ini->_loadIniFile('/home/www-data/...')
#2 /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Application.php(386): Zend_Config_Ini->__construct('/home/www-data/...', 'development')
#3 /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Application.php(85): Zend_Application->_loadConfig('/home/www-data/...')
#4 /home/www-data/zend.danielgroves.net/htdocs/public/index.php(24): Zend_Application->__construct('development', '/home/www-data/...')
#5 {main}
  thrown in /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Config/Ini.php on line 182

编辑2:

好的,我刚刚尝试了下面罗斯史密斯二世在回答中提出的建议。我的 application.ini 文件现在显示:

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

resources.frontController.params.displayExceptions = 0

resources.db.adapter = "Pdo_Mysql"
resources.db.params.charset = "utf8"
resources.db.params.host = "localhost"
resources.db.params.username = ""
resources.db.params.password = ""
resources.db.params.dbname = ""

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.defaultModule = "admin"
resources.layout.layoutPath = APPLICATION_PATH "/modules/admin/layouts/scripts/"
resources.modules[] =

[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

我在浏览器中收到此错误:

Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Controller/Dispatcher/Standard.php:248 Stack trace: #0 /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch() #2 /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() #3 /home/www-data/zend.danielgroves.net/htdocs/public/index.php(26): Zend_Application->run() #4 {main} Next exception 'Zend_Controller_Exception' with message 'Invalid controller specified (error)#0 /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(O in /home/www-data/zend.danielgroves.net/htdocs/library/Zend/Controller/Plugin/Broker.php on line 336

自己看看:http: //zend.danielgroves.net/admin/auth/

编辑 3

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

resources.frontController.params.displayExceptions = 0

resources.db.adapter = "Pdo_Mysql"
resources.db.params.charset = "utf8"
resources.db.params.host = "localhost"
resources.db.params.username = ""
resources.db.params.password = ""
resources.db.params.dbname = ""

resources.modules[] = ""

[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
4

3 回答 3

0

让模块在 Zend 中正常工作是非常具有挑战性的。我们遇到了许多意想不到的问题,例如正在初始化多个数据库连接(每个模块一个)。

首先,我将更改您application.ini的内容以包括以下内容:

resources.frontController.controllerDirectory = APPLICATION_PATH "/modules/Admin/controllers"
resources.frontController.defaultModule = "Admin"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"

resources.layout.layoutPath = APPLICATION_PATH "/modules/Admin/layouts/scripts/"

resources.modules[] =

如果这没有帮助,请尝试更改Admin为,admin因为我们从未使用过大写的模块名称。

如果您仍然卡住,请发布您的application.ini文件。

于 2012-07-19T14:42:25.380 回答
0

为了使模块在 ZF 1.11 的应用程序中工作,我所添加的只是我的 application.ini 中的这三行。

resources.frontController.moduleControllerDirectoryName = "controllers"
resources.modules = ""
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"

还要使自动加载正常工作,请确保您不要忘记Bootstrap.php在每个模块中放置一个空,如下所示:

<?php
class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
{
    //put your code here
}

它也可能有助于一些配置来指定默认模块的前缀,我的看起来像:

resources.frontController.params.prefixDefaultModule = ""

我的默认模块是控制器、模型和视图的原始应用程序目录。很像您当前的配置。

[编辑]

好吧,你已经陷入了一些混乱,也许你看看 Rob Allen 关于ZF 1.x 模块的教程,这就是我学到的地方。

于 2012-07-20T12:58:09.957 回答
0

这是我几个月前做的事情

您可以在https://github.com/harikt/blog查看整个代码

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
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
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] = ""
autoloadernamespaces[] = "BinaryKitten"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.view[] = 

[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

在 Bootstrap.php 中

<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    public function _initControllerPlugins()
    {
        $plugin = Zend_Controller_Front::getInstance()->registerPlugin(
            new BinaryKitten_ModuleConfig()
        );
    }

    public function _initAutoload()
    {
        $moduleLoader = new Zend_Application_Module_Autoloader(
            array(
                'namespace' => '',
                'basePath'  => APPLICATION_PATH . "/modules/default"
            )
        );
        return $moduleLoader;
    }
}

希望这有助于解决您的问题。

于 2012-07-24T07:10:42.100 回答