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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9051993/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 06:03:18  来源:igfitidea点击:

Zend Framework - "Invalid controller specified"

phpzend-framework

提问by

I have a problem with setting up my Zend Framework application on live server. It works alright on localhost.

我在实时服务器上设置 Zend Framework 应用程序时遇到问题。它在本地主机上工作正常。

My live server address where I have the application is:

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

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

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

Everything is OK until I try to access my admin module at URL http://www.domainname.com/new/admin, then I get the error below.

一切正常,直到我尝试通过 URL http://www.domainname.com/new/admin访问我的管理模块,然后我收到以下错误。

Any ideas?

有任何想法吗?

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',
)  

Include paths in index.php are set correctly (library and everything else is loaded), index.php file here:

正确设置 index.php 中的包含路径(库和其他所有内容都已加载),这里的 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 file:

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 file:

应用程序.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

采纳答案by Andy Baird

In your admin module folder, check that IndexController.php exists within the "controllers" sub-directory.

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

If it does, then open IndexController.php and ensure that the class declaration does indeed declare the class "IndexController" (a common copy+paste pitfall)

如果是,则打开 IndexController.php 并确保类声明确实声明了类“IndexController”(常见的复制+粘贴陷阱)

Edit: Controller name should be Admin_IndexController, not just IndexController

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

回答by RockyFord

try in your application.ini:

在您的 application.ini 中尝试:

resources.frontController.moduleControllerDirectoryName = "controllers"

I also have this in my application.ini for my module app:

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

resources.frontController.params.prefixDefaultModule = ""

also does each module have it's own bootstrap?

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

<?php

class Admin_Bootstrap extends Zend_Application_Module_Bootstrap {
    //put your code here
}

回答by Casso

I was using an authetication controller my collegue prepared and I had the same problem, and I found the problem in the redirect of the controller.

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

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

This basically checkes if you are logged in and if you have the access rights to go to the specified controller, and if not, it redirects you to (in this case) default/authenticaion/index Unfortunately the redirect parameters are not displayed in the error message. I realized I do not have the controller I am redirecting to ready, so in some cases it might be the same problem.

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