2011-03-31 97 views
1

是的,我已經訪問了論壇&試圖解決這個錯誤。 PLease我真的需要一點幫助。指定的控制器無效 - Zend Framework

每當我試圖訪問http://domain.com/dashboard/index/index/

我收到一個錯誤Invalid controller class ("Dashboard_IndexController")

有我的應用程序的主(默認)&儀表板兩個模塊

我的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()); 
     } 

    } 

任何想法。感謝您的支持

好男人我照顧。這在加載時

+1

看起來像名稱空間/類名問題。你有一個名爲Dashboard_IndexController的類嗎? – 2011-03-31 08:36:52

回答

1

您指定了儀表盤的命名空間中的一些路徑問題:

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

因此,將追加儀表板您嘗試調用所有類。因此,將名稱空間更改爲空字符串,並只保留一個Zend_Application_Module_Autoloader調用。我這樣做如下:

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

就是這樣!

0

或者你可以在一個ini文件中做到這一點。

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

//定義應用程序環境 defined('APPLICATION_ENV') || define('APPLICATION_ENV',(getenv('APPLICATION_ENV')?getenv('APPLICATION_ENV'):'production'));

//確保庫/是上的include_path 通過set_include_path(破滅(PATH_SEPARATOR,陣列( 真實路徑(APPLICATION_PATH '/../library'), get_include_path(), )));

/** Zend_Application */ require_once'Zend/Application。PHP的「;

//創建應用程序,引導和運行 $應用=新Zend_Application( APPLICATION_ENV, APPLICATION_PATH '/configs/application.ini' 。); $ application-> bootstrap() - > run();

相關問題