指定的控制器无效 - Zend Framework

时间:2011-03-31 08:34:44

标签: zend-framework zend-controller

是的,我已经访问了论坛&试图解决这个bug。我真的需要一点帮助。

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

我收到错误Invalid controller class ("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());
        }

    }

任何想法。感谢您的支持

好的伙计我照顾好了。加载时出现一些路径问题

2 个答案:

答案 0 :(得分:1)

您已在:

中指定了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;
}

就是这样!

答案 1 :(得分:0)

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

;custom name space

autoloaderNamespaces [] =&#34; Zfcms _&#34;

autoloaderNamespaces [] =&#34; App _&#34;

autoloaderNamespaces [] =&#34;自定义_&#34;

的index.php:

// Define path to application directory

定义(&#39; APPLICATION_PATH&#39;)     ||定义(&#39; APPLICATION_PATH&#39;,realpath(dirname( FILE )。&#39; /../ application&#39;));

//定义应用程序环境 定义(&#39; APPLICATION_ENV&#39;)     ||定义(&#39; APPLICATION_ENV&#39;,(getenv(&#39; APPLICATION_ENV&#39;)?getenv(&#39; APPLICATION_ENV&#39;):&#39; production&#39;));

//确保library /在include_path上 set_include_path(implode(PATH_SEPARATOR,array(     realpath(APPLICATION_PATH。&#39; /../ library&#39;),     get_include_path() )));

/ ** Zend_Application * / require_once&#39; Zend / Application.php&#39;;

//创建应用程序,引导程序和运行 $ application = new Zend_Application(     APPLICATION_ENV,     APPLICATION_PATH。 &#39; /configs/application.ini' ); $应用 - &GT;自举()              - &gt;运行();