指定的控制器无效 - Zend Framework

发布于 2024-10-28 15:28:42 字数 6397 浏览 3 评论 0原文

是的,我已经访问过论坛和论坛了。尝试解决该错误。请我在这里真的需要一点帮助。

每当我尝试访问 http://domain.com/dashboard/index/index/

我收到错误无效的控制器类(“Dashboard_IndexController”)

我的应用程序中有两个模块 Main(默认)&仪表板

我的 Application.ini

[bootstrap]
autoloadernamespaces[] = "Zend_"
autoloadernamespaces[] = "WOW_"

phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"

bootstrap.class = "Bootstrap"

resources.frontcontroller.moduledirectory = APPLICATION_PATH"/modules"
resources.frontcontroller.defaultmodule = "main"
resources.frontcontroller.params.prefixDefaultModule = true

resources.frontController.params.displayExceptions = 0
resources.frontcontroller.throwerrors = false

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.layout.layout =  "main"

resources.view[] =

resources.modules[] =

Bootstrap.php

<?php

    class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
    {

        protected $_logger;


        protected $_resourceLoader;


        public $frontController;

        protected function _initLogging()
        {
             $this->bootstrap('frontController');
    //       $this->frontController = $this->getResource('frontController');
            $logger = new Zend_Log();

            $writer = 'production' == $this->getEnvironment() ?
                new Zend_Log_Writer_Stream(APPLICATION_PATH . '/../data/logs/app.log') :
                new Zend_Log_Writer_Firebug();
            $logger->addWriter($writer);


                $filter = new Zend_Log_Filter_Priority(Zend_Log::CRIT);
                $logger->addFilter($filter);


            $this->_logger = $logger;
            Zend_Registry::set('log', $logger);
        }
        protected function _initDoctype()
        {
            $this->bootstrap('view');
            $view = $this->getResource('view');
            $view->doctype('XHTML1_STRICT');
        }


        protected function _initDbProfiler()
        {
            $this->_logger->info('Bootstrap ' . __METHOD__);

            if ('production' !== $this->getEnvironment()) {
                $this->bootstrap('db');
                $profiler = new Zend_Db_Profiler_Firebug('All DB Queries');
                $profiler->setEnabled(true);
                $this->getPluginResource('db')->getDbAdapter()->setProfiler($profiler);
            }
        }


        protected function _initConfig()
        {
            $this->_logger->info('Bootstrap ' . __METHOD__);
            Zend_Registry::set('config', $this->getOptions());
        }


        protected function _initRoutes()
        {

            $this->_logger->info('Bootstrap ' . __METHOD__);
            $this->bootstrap('frontController');

            $router = $this->frontController->getRouter();

            // Admin context route
            $route = new Zend_Controller_Router_Route(
                'dashboard',
                array(
                    'action'     => 'index',
                    'controller' => 'index',
                    'module'     => 'dashboard',
                    'isAdmin'    => true
                )
            );

            $router->addRoute('dashboard', $route);


        }


        protected function _initDefaultModuleAutoloader()
        {
            $this->_logger->info('Bootstrap ' . __METHOD__);

            $this->_resourceLoader = new Zend_Application_Module_Autoloader(array(
                'namespace' => 'Main',
                'basePath'  => APPLICATION_PATH . '/modules/main',
            ));
            $this->_resourceLoader->addResourceTypes(array(
                'modelResource' => array(
                  'path'      => 'models/resources',
                  'namespace' => 'Resource',
                ),

                'form' => array(
                        'path' => 'forms',
                        'namespace' => 'Form',
                   ),

                'service' => array(
                        'path' => 'services',
                        'namespace' => 'Service',
                        ),

            ));
            /*
             $this->frontController->setControllerDirectory(array(
                    'default' => APPLICATION_PATH .'/modules/main/controllers',
                    'dashboard' => APPLICATION_PATH .'/modules/dashboard/controllers',

            ));
              yeah I tried this too....
            */

        }
        /**
         * function autoloads the different modules 
         */

        protected function _initModuleLoader()
        {
            $this->_logger->info('Bootstrap ' . __METHOD__);

            $this->_resourceLoader = new Zend_Application_Module_Autoloader(array(
                'namespace' => 'Dashboard',
                'basePath'  => APPLICATION_PATH . '/modules/dashboard',
            ));
            $this->_resourceLoader->addResourceTypes(array(
                'modelResource' => array(
                  'path'      => 'models/resources',
                  'namespace' => 'Resource',
                ),

                /*
                'form' => array(
                        'path' => 'form',
                        'namespace' => 'Form',
                   ),

                'service' => array(
                        'path' => 'services',
                        'namespace' => 'Service',
                        ),
               */
            ));

        }


         /**
         * Add Controller Action Helpers
         */
        protected function _initActionHelpers()
        {
            $this->_logger->info('Bootstrap ' . __METHOD__);
           // Zend_Controller_Action_HelperBroker::addHelper(new WOW_Controller_Helper_Acl());
           // Zend_Controller_Action_HelperBroker::addHelper(new SF_Controller_Helper_RedirectCommon());
            // Zend_Controller_Action_HelperBroker::addHelper(new SF_Controller_Helper_Service());
        }

    }

任何想法。感谢你们的支持

,好吧,我已经处理好了。加载时出现一些路径问题

Yeah I have already visited the forums & tried to solve the bug. PLease I really need a little help here.

Whenever I am trying to access the http://domain.com/dashboard/index/index/

I receive an error Invalid controller class ("Dashboard_IndexController")

There are two modules in my application Main (default) & Dashboard

My Application.ini

[bootstrap]
autoloadernamespaces[] = "Zend_"
autoloadernamespaces[] = "WOW_"

phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"

bootstrap.class = "Bootstrap"

resources.frontcontroller.moduledirectory = APPLICATION_PATH"/modules"
resources.frontcontroller.defaultmodule = "main"
resources.frontcontroller.params.prefixDefaultModule = true

resources.frontController.params.displayExceptions = 0
resources.frontcontroller.throwerrors = false

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.layout.layout =  "main"

resources.view[] =

resources.modules[] =

Bootstrap.php

<?php

    class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
    {

        protected $_logger;


        protected $_resourceLoader;


        public $frontController;

        protected function _initLogging()
        {
             $this->bootstrap('frontController');
    //       $this->frontController = $this->getResource('frontController');
            $logger = new Zend_Log();

            $writer = 'production' == $this->getEnvironment() ?
                new Zend_Log_Writer_Stream(APPLICATION_PATH . '/../data/logs/app.log') :
                new Zend_Log_Writer_Firebug();
            $logger->addWriter($writer);


                $filter = new Zend_Log_Filter_Priority(Zend_Log::CRIT);
                $logger->addFilter($filter);


            $this->_logger = $logger;
            Zend_Registry::set('log', $logger);
        }
        protected function _initDoctype()
        {
            $this->bootstrap('view');
            $view = $this->getResource('view');
            $view->doctype('XHTML1_STRICT');
        }


        protected function _initDbProfiler()
        {
            $this->_logger->info('Bootstrap ' . __METHOD__);

            if ('production' !== $this->getEnvironment()) {
                $this->bootstrap('db');
                $profiler = new Zend_Db_Profiler_Firebug('All DB Queries');
                $profiler->setEnabled(true);
                $this->getPluginResource('db')->getDbAdapter()->setProfiler($profiler);
            }
        }


        protected function _initConfig()
        {
            $this->_logger->info('Bootstrap ' . __METHOD__);
            Zend_Registry::set('config', $this->getOptions());
        }


        protected function _initRoutes()
        {

            $this->_logger->info('Bootstrap ' . __METHOD__);
            $this->bootstrap('frontController');

            $router = $this->frontController->getRouter();

            // Admin context route
            $route = new Zend_Controller_Router_Route(
                'dashboard',
                array(
                    'action'     => 'index',
                    'controller' => 'index',
                    'module'     => 'dashboard',
                    'isAdmin'    => true
                )
            );

            $router->addRoute('dashboard', $route);


        }


        protected function _initDefaultModuleAutoloader()
        {
            $this->_logger->info('Bootstrap ' . __METHOD__);

            $this->_resourceLoader = new Zend_Application_Module_Autoloader(array(
                'namespace' => 'Main',
                'basePath'  => APPLICATION_PATH . '/modules/main',
            ));
            $this->_resourceLoader->addResourceTypes(array(
                'modelResource' => array(
                  'path'      => 'models/resources',
                  'namespace' => 'Resource',
                ),

                'form' => array(
                        'path' => 'forms',
                        'namespace' => 'Form',
                   ),

                'service' => array(
                        'path' => 'services',
                        'namespace' => 'Service',
                        ),

            ));
            /*
             $this->frontController->setControllerDirectory(array(
                    'default' => APPLICATION_PATH .'/modules/main/controllers',
                    'dashboard' => APPLICATION_PATH .'/modules/dashboard/controllers',

            ));
              yeah I tried this too....
            */

        }
        /**
         * function autoloads the different modules 
         */

        protected function _initModuleLoader()
        {
            $this->_logger->info('Bootstrap ' . __METHOD__);

            $this->_resourceLoader = new Zend_Application_Module_Autoloader(array(
                'namespace' => 'Dashboard',
                'basePath'  => APPLICATION_PATH . '/modules/dashboard',
            ));
            $this->_resourceLoader->addResourceTypes(array(
                'modelResource' => array(
                  'path'      => 'models/resources',
                  'namespace' => 'Resource',
                ),

                /*
                'form' => array(
                        'path' => 'form',
                        'namespace' => 'Form',
                   ),

                'service' => array(
                        'path' => 'services',
                        'namespace' => 'Service',
                        ),
               */
            ));

        }


         /**
         * Add Controller Action Helpers
         */
        protected function _initActionHelpers()
        {
            $this->_logger->info('Bootstrap ' . __METHOD__);
           // Zend_Controller_Action_HelperBroker::addHelper(new WOW_Controller_Helper_Acl());
           // Zend_Controller_Action_HelperBroker::addHelper(new SF_Controller_Helper_RedirectCommon());
            // Zend_Controller_Action_HelperBroker::addHelper(new SF_Controller_Helper_Service());
        }

    }

Any Idea. Thanks for ur support

Ok Guys I took care of that. That some path problem at loading time

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仅冇旳回忆 2024-11-04 15:28:42

您已在以下位置指定了 Dashboard 命名空间:

    $this->_resourceLoader = new Zend_Application_Module_Autoloader(array(
        'namespace' => 'Dashboard',
        'basePath'  => APPLICATION_PATH . '/modules/dashboard',
    ));

因此它将把 Dashboard 附加到您尝试调用的所有类中。因此,将命名空间更改为空字符串,并仅保留一个 Zend_Application_Module_Autoloader 调用。我正在这样做:

protected function _initModule() {
    $loader = new Zend_Application_Module_Autoloader(array(
        'namespace' => '',
        'basePath' => APPLICATION_PATH,
    ));
    return $loader;
}

就是这样!

You had specified Dashboard namespace in:

    $this->_resourceLoader = new Zend_Application_Module_Autoloader(array(
        'namespace' => 'Dashboard',
        'basePath'  => APPLICATION_PATH . '/modules/dashboard',
    ));

So it will append Dashboard to ALL classes you try to call. So change namespace to empty string and leave only one Zend_Application_Module_Autoloader call. I'm doing it like the following:

protected function _initModule() {
    $loader = new Zend_Application_Module_Autoloader(array(
        'namespace' => '',
        'basePath' => APPLICATION_PATH,
    ));
    return $loader;
}

And that's it!

狂之美人 2024-11-04 15:28:42

或者您可以在 ini 文件中执行此操作。

;custom name space

autoloaderNamespaces[] = "Zfcms_"

autoloaderNamespaces[] = "App_"

autoloaderNamespaces[] = "Custom_"

index.php:

// Define path to application directory

已定义('APPLICATION_PATH')
|| Define('APPLICATION_PATH', realpath(dirname(FILE) . '/../application'));

// 定义应用环境
定义('APPLICATION_ENV')
||定义('APPLICATION_ENV',(getenv('APPLICATION_ENV')?getenv('APPLICATION_ENV'):'生产'));

// 确保library/在include_path上
set_include_path(内爆(PATH_SEPARATOR,数组(
真实路径(APPLICATION_PATH。'/../library'),
获取包含路径(),
)));

/** Zend_Application */
require_once 'Zend/Application.php';

// 创建应用程序,引导并运行
$application = 新 Zend_Application(
应用程序_ENV,
应用程序路径。 '/configs/application.ini'
);
$应用程序-> bootstrap()
-> 运行();

Or you can do it within an ini file.

;custom name space

autoloaderNamespaces[] = "Zfcms_"

autoloaderNamespaces[] = "App_"

autoloaderNamespaces[] = "Custom_"

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

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));

/** 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();

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文