Zend框架-“;指定的控制器无效”;


Zend Framework - "Invalid controller specified"

我在实时服务器上设置Zend Framework应用程序时遇到问题。它在本地主机上运行良好。

我有应用程序的实时服务器地址是:

http://www.domainname.com/new/

在我尝试访问URL上的管理模块之前,一切都很好http://www.domainname.com/new/admin,然后我得到下面的错误。

有什么想法吗?

An error occurred
Page not found
Exception information:
Message: Invalid controller specified (index)
Stack trace:
#0 /data/www/www.domainname.com/public_html/new/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#1 /data/www/www.domainname.com/public_html/new/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#2 /data/www/www.domainname.com/public_html/new/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#3 /data/www/www.domainname.com/public_html/new/index.php(27): Zend_Application->run()
#4 {main}  
Request Parameters:
array (
  'module' => 'admin',
  'controller' => 'index',
  'action' => 'index',
)  

index.php中的Include路径设置正确(库和其他所有内容都已加载),此处的index.php文件:

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));
// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
set_include_path('library');
// Define upload path
if (!defined('UPLOAD_PATH'))
        define('UPLOAD_PATH', realpath(dirname(__FILE__)) . '/upload/');
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
            ->run();

Bootstrap.php文件:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initDoctype(){
        $this->bootstrap('view');
        $view = $this->getResource('view');
        $view->doctype('XHTML1_STRICT');
    }
    protected function _initTimeZone(){
        $date = $this->getOption('date');
        date_default_timezone_set($date['timezone']);
    }
    protected function _initLayoutHelper(){
        $this->bootstrap('frontController');
        Zend_Controller_Action_HelperBroker::addHelper(
            new Jakub_Controller_Action_Helper_LayoutLoader());
    }
    protected function _initFlashMessenger(){
        $flashMessenger = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');
        if ($flashMessenger->hasMessages()) {
            $view = $this->getResource('view');
            $view->messages = $flashMessenger->getMessages();
        }
    }
    protected function _initAuth(){
        $this->bootstrap('session');
        $auth = Zend_Auth::getInstance();
        if ($auth->hasIdentity()) {
            $view = $this->getResource('view');
            $view->user = $auth->getIdentity();
        }
        return $auth;
    }
}

Application.ini文件:

[production]
webhost = "http://www.domainname.com/new"
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
includePaths.library = APPLICATION_PATH "/../library"
date.timezone = "Europe/Bratislava"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
autoloadernamespaces.nette = "Nette_"
autoloadernamespaces.jakub = "Jakub_"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.view[] =
resources.view.helperPath.App_View_Helper = APPLICATION_PATH "/views/helpers"
resources.modules[] =
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/default/"
resources.layout.layout = default
admin.resources.layout.layoutPath = APPLICATION_PATH "/modules/admin/layouts/scripts/base/"
admin.resources.layout.layout = default
[staging : production]
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
webhost = "http://domainname"
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

在管理模块文件夹中,检查IndexController.php是否存在于"controllers"子目录中。

如果是,那么打开IndexController.php并确保类声明确实声明了类"IndexController"(一个常见的复制+粘贴陷阱)

编辑:控制器名称应该是Admin_IndexController,而不仅仅是IndexController

在您的应用程序中尝试.ini:

resources.frontController.moduleControllerDirectoryName = "controllers"

我的模块应用程序的application.ini中也有这个:

resources.frontController.params.prefixDefaultModule = ""

每个模块都有自己的引导程序吗?

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

我使用的是我的同事准备的身份验证控制器,我也遇到了同样的问题,我在控制器的重定向中发现了问题。

if (!$this->_acl->isAllowed(Zend_Registry::get('user_role'), $module . ':' . $controller, $action)) {
$request->setModuleName('default')->setControllerName('authentication')->setActionName('login');}

这基本上会检查您是否登录,是否有访问指定控制器的权限,如果没有,它会将您重定向到(在本例中)default/authentication/index遗憾的是,重定向参数没有显示在错误消息中。我意识到我没有准备好重定向到的控制器,所以在某些情况下可能是同样的问题。