1

我试图了解 Zend 框架是如何工作的。这些模型是否设计成这样的事情?我只有一个基本的设置,所以我可以在我的控制器中使用这样的东西:

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

您能否也给我一个关于如何在控制器上使用它的示例?

class Country extends Zend_Db_Table
{

    protected $_name = 'country';

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

}

此致!

4

2 回答 2

3

Pedantic terminology: Zend_Db_Table是一个表示数据库表的类。这与 MVC 意义上的模型不同

我为组件编写了很多文档,Zend_Db但我没有将表和模型视为同义词(就像许多框架一样)。

另请参阅我写的关于此主题的博客:

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

于 2009-06-25T19:45:44.110 回答
2

Zend 模型旨在链接到表格并帮助您与表格进行交互。

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'));

手册中的更多信息

于 2009-06-24T16:33:17.543 回答