2010-06-09 169 views
1

添加操作助手類後,出現致命錯誤。我正在嘗試加載對應於調用佈局的佈局。以下是我的代碼片段:Zend框架控制器操作助手

class Zend_Controller_Action_Helper_Layout extends Zend_Controller_Action_Helper_Abstract { 

public $pluginLoader; 


public function __construct() 
{ 
    // TODO Auto-generated Constructor 
    $this->pluginLoader = new Zend_Loader_PluginLoader(); 
} 


public function preDispatch() 
{ 
     $bootstrap = $this->getActionController()->getInvokeArg('bootstrap'); 
     $config = $bootstrap->getOptions(); 
     $module = $this->getRequest()->getModuleName(); 
     if (isset($config[$module]['resources']['layout']['layout'])) { 
      $layoutScript = $config[$module]['resources']['layout']['layout']; 
      $this->getActionController()->getHelper('layout')->setLayout($layoutScript); 
     } 

    } 

} 

然後我說在bootstrap.php中裝載機:

protected function _initLayoutHelper() { 

    $this->bootstrap('frontController'); 
    Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH .'/controllers/helpers'); 

    $layout = Zend_Controller_Action_HelperBroker::addHelper(new Zend_Controller_Action_Helper_Layout()); 
} 

所有加入我正在申請/控制器/傭工一個輔助類的第一

以下是我的application.ini:

[production] 
autoloaderNamespaces.tree = "Tree_" 
phpSettings.display_startup_errors = 0 
phpSettings.display_errors = 0 
includePaths.library = APPLICATION_PATH "/../library" 
bootstrap.path = APPLICATION_PATH "/Bootstrap.php" 
bootstrap.class = "Bootstrap" 
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" 
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules" 
resources.frontController.helperDirectory = APPLICATION_PATH "/controllers/helpers" 

resources.modules[] = "" 
contact.resources.frontController.defaultControllerName = "index" 
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts" 
resources.layout.layout = layout 
admin.resources.layout.layout = admin 
#admin.resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts" 

resources.view[] = 

[staging : production] 

[testing : production] 
phpSettings.display_startup_errors = 1 
phpSettings.display_errors = 1 

[development : production] 
phpSettings.display_startup_errors = 1 
phpSettings.display_errors = 1 

當運行此代碼我收到以下錯誤:

Warning: include(Zend\Controller\Action\Helper\LayoutLoader.php) [function.include]: failed to open stream: No such file or directory in D:\personal\proj\renovate\library\Zend\Loader.php on line 83

Warning: include() [function.include]: Failed opening 'Zend\Controller\Action\Helper\LayoutLoader.php' for inclusion (include_path='D:\personal\proj\renovate\application/../library;D:\personal\proj\renovate\library;.;C:\php5\pear') in D:\personal\proj\renovate\library\Zend\Loader.php on line 83

Fatal error: Class 'Zend_Controller_Action_Helper_LayoutLoader' not found in D:\personal\proj\renovate\application\Bootstrap.php on line 33

請讓我知道,我怎麼可以從這個問題出來了。我是Zend Framework的初學者。

回答

0

好像你有無效include_path

嘗試插入這個在index.php:

 

define('ROOTDIR', dirname(__FILE__) . DIRECTORY_SEPARATOR); 
define('LIBDIR', realpath(ROOTDIR . '../library') . DIRECTORY_SEPARATOR); 
set_include_path(implode(PATH_SEPARATOR, array_merge(explode(PATH_SEPARATOR,ini_get('include_path')), array(LIBDIR)))); 
 

這適用於像目錄結構:

 
application/ 
library/ 
- Zend/ 
httpdocs/ 
- index.php 
0

我覺得包括路徑是否有效。以下是我的index.php

//定義應用程序目錄的路徑 defined('APPLICATION_PATH')|| define('APPLICATION_PATH',realpath(dirname(FILE)。'/../application'));

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

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

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

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