2009-10-15 117 views
2

我使用Zend 1.8.4並設置了一個簡單的表單測試。我的表單類位於「./application/forms/SectorSearch.php」和類名是Zend表單模塊包含路徑

<?php 
class Form_SectorSearch extends Zend_Form 
{...} 

我的控制器在init()方法

<?php 
class SectorController extends Zend_Controller_Action 
{ 
    function init() 
    { 
     $this->initView(); 
     $form = new Form_SectorSearch(array(
      'method' => '/public/sector/search', 
      'action' => 'post')); 
     $this->view->form = $form; 
    } 
.. 
} 

但我創建了一個新形式得到這個錯誤

Warning: Zend_Loader_Autoloader_Resource::include(/home/poconnell/projects/bhaa/application/forms/SectorSearch.php) [zend-loader-autoloader-resource.include]: failed to open stream: No such file or directory in /home/poconnell/projects/bhaa/library/Zend/Loader/Autoloader/Resource.php on line 178 

Warning: Zend_Loader_Autoloader_Resource::include() [function.include]: Failed opening '/home/poconnell/projects/bhaa/application/forms/SectorSearch.php' for inclusion (include_path='/home/poconnell/projects/bhaa/library:/home/poconnell/projects/bhaa/application:.:/usr/share/php:/usr/share/pear') in /home/poconnell/projects/bhaa/library/Zend/Loader/Autoloader/Resource.php on line 178 

Fatal error: Class 'Form_SectorSearch' not found in /home/poconnell/projects/bhaa/application/controllers/SectorController.php on line 19 

我100%確定這個類是包含路徑。

我認爲這是一個問題,Bootstrap逼近,這是如何我加載默認模塊

protected function _initAutoload() 
{ 
    //Zend_Loader_Autoloader_Resource - Zend_Application_Module_Autoloader 
    $moduleLoader = new Zend_Application_Module_Autoloader(array(
     'namespace' => '', 
     'basePath' => APPLICATION_PATH 
    )); 
    return $moduleLoader; 
} 

我甚至使用這種模式嘗試的建議,Autloading modular forms & models in Zend Framework 1.8

protected function _initAutoload() 
{ 
    //Zend_Loader_Autoloader_Resource - Zend_Application_Module_Autoloader 
    $moduleLoader = new Zend_Application_Module_Autoloader(array(
     'namespace' => '', 
     'basePath' => APPLICATION_PATH, 
     'resourceTypes' => array (
      'form' => array(
      'path' => 'forms', 
      'namespace' => 'Form')) 
    ); 
    return $moduleLoader; 
} 

但沒有喜悅。有任何想法嗎?

+0

注意文件名在UperCase中包含它們。從win到linux切換時這是常見的問題。 – powtac 2009-10-15 13:15:24

+0

你是否100%確定該文件具有正確的權限? – PatrikAkerstrand 2009-10-15 13:24:46

+0

poconnell @ foundry:〜/ projects/bhaa/application/forms $ ls -al SectorSearch.php -rw-r - r-- 1 poconnell poconnell 561 2009-10-15 14:41 SectorSearch.php – emeraldjava 2009-10-15 14:03:48

回答

1

確保大小寫完全匹配。 該文件夾,除非你指定不同的目錄Form類被命名爲形式,確保SectorSearch不是sEcTorSEarcH.php什麼

0

Zend框架解釋在類名作爲文件夾下劃線。如果你手動添加application/forms文件夾到include路徑,那麼你應該命名你的類FormSectorSearch(和文件名FormSectorSearch.php)而不是Form_SectorSearch。否則,您只會將應用程序文件夾添加到包含路徑中,然後將該文件夾命名爲Form而不是表單。

2

添加以下到我的bootstrap.php文件

protected function _initAutoload() 
    { 
     $autoloader = new Zend_Loader_Autoloader_Resource(array(
      'namespace' => '', 
      'basePath' => APPLICATION_PATH, 
      'resourceTypes' => array(
       'form' => array(
        'path' => 'forms', 
        'namespace' => 'Form', 
       ), 
       'model' => array(
        'path' => 'models', 
        'namespace' => 'Model', 
       ), 
      ) 
     )); 
     return $autoloader; 
    } 

,現在它的作品,沒有任何錯誤了..哎呀我很高興它的工作原理,我幾乎要瘋了.. :)

+0

是否知道是否有可以添加的配置條目以便找到它? – jackyalcine 2012-06-01 01:28:54