1

I'm trying to understand how the Zend Framework works.Are the models designed to do something like this?I have just a basic setup, so I can use in my controllers something like this:

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

Can you also give me an example on how to use this on a controller?

class Country extends Zend_Db_Table
{

    protected $_name = 'country';

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

}

Best Regards!

2 Answers 2

3

Pedantic terminology: Zend_Db_Table is a class to represent database tables. This is not the same thing as a Model in the MVC sense.

I wrote a lot of the documentation for the Zend_Db components, and nowhere did I treat Tables and Models as synonyms (as many frameworks do).

Also see a blog I wrote on this subject:

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

Sign up to request clarification or add additional context in comments.

Comments

2

Zend Models are desigend to be linked to a table and help you to interact with a table.

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

more informations in the manual

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.