2010-09-01 88 views
0

我有一個文件夾結構像this,我試圖加載News模型我的控制器內:問題加載模式與Zend框架模塊

<?php 
/** 
* Login 
*/ 
class Admin_NewsController extends Zend_Controller_Action { 

    public function preDispatch() { 
     $layout = Zend_Layout::getMvcInstance(); 
     $layout->setLayout('admin'); 
    } 
    public function init() { 
     $this->db = new Application_Admin_Model_DbTable_News(); 
    } 

    public function indexAction() { 

    } 

    public function addAction() { 
     //$this->getHelper('viewRenderer')->setNoRender(); 
     // Calls the Request object 
     $request = $this->getRequest(); 

     if ($request->isPost()) { 
      // Retrieves form data 
      $data = array(
       "new_title" => $request->getParam('txtTitle'), 
       "new_text" => htmlentities($request->getParam('txtNews')), 
       "new_image" => $request->getParam('upName'), 
       "new_published" => 1 
      ); 
      // Inserts in the database 
      if ($this->db->addNews($data)) { 
       $this->view->output = 1; 
      } else { 
       $this->view->output = 0; 
      } 
     } else { 
      $this->view->output = 0; 
     } 

     $this->_helper->layout->disableLayout(); 
    } 
} 

而且我模式

<?php 

class Application_Admin_Model_DbTable_News extends Zend_Db_Table_Abstract 
{ 
    protected $_name = 'news'; 

    public function addNews($data) { 
     $this->insert($data); 
    } 
} 

Althoug我得到這個錯誤: alt text

回答

1

S因此你的新聞類屬於該模塊,其名稱應該是Admin_Model_DbTable_News,不含Application_前綴。

看到http://framework.zend.com/manual/en/zend.loader.autoloader-resource.html#zend.loader.autoloader-resource.module

+1

確定更多的模塊中自動加載,但現在它說'致命錯誤:類「Admin_Model_DbTable_News」不found' – 2010-09-01 16:46:57

+0

我一定要使用一些自動加載磁帶機? – 2010-09-01 16:52:53

+0

您需要確保的唯一一件事就是您的模塊引導程序正在擴展Zend_Application_Module_Bootstrap,如下所示: class News_Bootstrap擴展了Zend_Application_Module_Bootstrap – Vika 2010-09-01 18:18:48