2014-02-07 86 views
2

我試圖在數據庫中插入數據,但有模型的問題。請幫助 致命錯誤:\瓦帕\ WWW \ MMZ \應用\控制器\ VendorController.php第9行zend框架1.12 - 致命錯誤:類'Model_DbTable_Vendor'找不到

應用/ CONFIGS /的application.ini

[production] 
phpSettings.display_startup_errors = 1 
phpSettings.display_errors = 1 
includePaths.library = APPLICATION_PATH "/../library" 
bootstrap.path = APPLICATION_PATH "/Bootstrap.php" 
bootstrap.class = "Bootstrap" 
appnamespace = "Application" 
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" 
resources.frontController.params.displayExceptions = 0 

resources.layout.layout = "layout" 
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts" 
[resources.frontController.baseUrl = "/mmz/public"] 
resources.view[] = "" 
resources.view.doctype = "html5" 
resources.view.encoding = "utf-8" 
resources.view.contentType = "text/html;charset=utf-8" 
resources.modules[] = "admin" 

resources.db.adapter = "pdo_mysql" 
resources.db.params.host = "localhost" 
resources.db.params.username = "root" 
resources.db.params.password = "" 
resources.db.params.dbname = "catalog" 
resources.db.isDefaultTableAdapter = true 
resources.db.params.charsert = "utf8" 

[staging : production] 
resources.view[] = 
[testing : production] 
phpSettings.display_startup_errors = 1 
phpSettings.display_errors = 1 

[development : production] 
phpSettings.display_startup_errors = 1 
phpSettings.display_errors = 1 
resources.frontController.params.displayExceptions = 1 
:類 'Model_DbTable_Vendor' 不在d發現

bootstrap.php中

<?php 

    class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { 

     protected function _initViewHelpers() { 
      $view = new Zend_View(); 
      $view->headTitle('Main Title')->setSeparator(' - '); 
     } 

    } 

應用程序/模型/ DBTABLE/Vendor.php

<?php 

require_once("Zend/Db/Table/Abstract.php"); 

class Model_DbTable_Vendor extends Zend_Db_Table_Abstract { 

    protected $_name = "vendor"; 

    public function init() { 

     $this->getAdapter()->query("SET NAMES 'utf8'"); 
    } 

    public function addVendor($vendor_name) { 
     $this->insert($vendor_name); 
    } 
} 

應用/表格/ Vendor.php

<?php 
class Application_Form_Vendor extends Zend_Form 
{ 
    public function init() 
    { 
     $this->setMethod('post'); 

     $this->addElement('text', 'vendor_name', array(
      'label'  => 'Vendor name:', 
      'required' => true, 
      'filters' => array('StringTrim') 
      // 'validators' => array(
      //  'EmailAddress', 
      //) 
     )); 

     $this->addElement('submit', 'submit', array(
      'ignore' => true, 
      'label' => 'Add new', 
     )); 

     $this->addElement('hash', 'csrf', array(
      'ignore' => true, 
     )); 
    } 
} 

應用/控制器/ VendorController.php

<?php 

class VendorController extends Zend_Controller_Action { 

    protected $vendor; 

    public function init() { 
     /* Initialize action controller here */ 
     $this->vendor = new Model_DbTable_Vendor(); 
    } 

    public function indexAction() { 
     $request = $this->getRequest(); 
     $form = new Application_Form_Vendor(); 
     $this->view->form = $form; 

     if ($this->getRequest()->isPost()) { 
      if ($form->isValid($request->getPost())) { 
       $vendor_name = $form->getValue('vendor_name'); 
       $this->vendor->addVendor($vendor_name); 
      } 
     } 

    } 

} 

應用/視圖/腳本/供應商/ index.phtml

Vendor form 
<?php 
$this->form->setAction($this->url()); 
echo $this->form; 
+0

哪裏是你的自動加載機安裝/配置?如果您沒有在自動加載器 – JamesHalsall

+0

不是'Model_'標準路徑註冊'Model_'命名空間,ZF將不知道在哪裏尋找您的Model類?我的猜測是,自動加載器會跳過模型類的路徑:嘗試使用與模型僞名稱空間完全相同的文件夾名稱:'application/models/DbTable/Vendor.php' – cypherabe

+0

use Application when從控制器調用模型。 –

回答

1

代替的,

public function init() { 
     /* Initialize action controller here */ 
     $this->vendor = new Model_DbTable_Vendor(); 
    } 

使用,

public function init() { 
     /* Initialize action controller here */ 
     $this->vendor = new Application_Model_DbTable_Vendor(); 
    } 

在.ini文件

resources.frontController.params.displayExceptions = 1 // error reporting on 
+0

OK,但是當我在我的應用改變/模型/ DBTABLE/Vendor.php Model_DbTable_Vendor()來Application_Model_DbTable_Vendor(),並在控制器相同的變化,我有這種情況: 出錯 應用程序錯誤 – zaca45

+0

你有沒有按照我的建議,請參閱上面的答案只更改控制器而不是模型文件,並在application.ini文件 –

+0

中打開錯誤報告並歡迎堆棧溢出,如果您發現答案有幫助,請參閱[接受答案](http: //meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) –

相關問題