指定的控制器无效(auth)

时间:2012-07-19 14:21:03

标签: zend-framework

我一直在尝试编写一个基本身份验证系统作为项目的一部分,我应该使用它来了解Zend Framework。我一直在使用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 Directory/File structure

非常感谢任何帮助。

编辑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:

好的,我刚刚尝试过以下Ross Smith II的回答中提出的建议。我的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

3 个答案:

答案 0 :(得分: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文件。

答案 1 :(得分:0)

我在应用程序中使用ZF 1.11在模块中工作的所有内容都是这三行。

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

还要使autoloadiong正常工作,确保您不要忘记在每个模块中放置一个空的Bootstrap.php

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

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

resources.frontController.params.prefixDefaultModule = ""

我的默认模块是控制器,模型和视图的原始应用程序目录。与您当前的配置非常相似。

<强> [编辑]

好的,你已经陷入了一些混乱,或许你可以在modules in ZF 1.x上了解Rob Allen的教程,这是我学到的。

答案 2 :(得分: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;
    }
}

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