2009-06-24 94 views
1

我想了解Zend框架works.Are專門做這樣的事情的模型我只是一個基本的設置,所以我可以在我的控制器是這樣使用:Zend框架模型

$db->query($this->selectAll()) 

你也可以給我一個關於如何在控制器上使用它的例子嗎?

class Country extends Zend_Db_Table 
{ 

    protected $_name = 'country'; 

    public function selectAll() 
    { 
     return 'SELECT * FROM'.$this->_name.''; 
    } 

} 

最好的問候!

回答

2

Zend Models被設計爲鏈接到一個表,並幫助您與表交互。

class BugsProducts extends Zend_Db_Table_Abstract 
{ 
    protected $_name = 'bugs_products'; 
    protected $_primary = array('bug_id', 'product_id'); 
} 

$table = new BugsProducts(); 

$rows = $table->fetchAll('bug_status = "NEW"', 'bug_id ASC', 10, 0); 
$rows = $table->fetchAll($table->select()->where('bug_status = ?', 'NEW') 
             ->order('bug_id ASC') 
             ->limit(10, 0)); 

// Fetching a single row 
$row = $table->fetchRow('bug_status = "NEW"', 'bug_id ASC'); 
$row = $table->fetchRow($table->select()->where('bug_status = ?', 'NEW') 
             ->order('bug_id ASC')); 

更詳細的信息在manual

3

迂腐術語:Zend_Db_Table是表示數據庫表的類。這是而不是與MVC意義上的模型相同。

我寫了很多關於Zend_Db組件的文檔,並且我沒有將表和模型看作同義詞(就像很多框架一樣)。

也看到了博客,我在這個問題上寫道:

http://karwin.blogspot.com/2008/05/activerecord-does-not-suck.html