Search code examples
phpzend-frameworkzend-dbzend-db-table

Zend Framework how to map DbTable model to database table and insert new row


I cannot figure out how to correctly map a DbTable model to a database row in a table in my DB and correspondingly extend this DbTable model to another model so that I can insert a new row. Any simple examples and explanation would be very helpful, as I am struggling in the logic of this problem. Thanks.


Solution

  • I figured it out. For example, in my Application_Model_DbTable_ExTable add

    protected $_name = 'ExTable';
    

    This way Zend will know which table in the database to use.

    I then extended Application_Model_DbTable_ExTable to my Application_Model_ExTable, and once I did that I was able to insert into my database using an array such as

    public function ExFunction ($example){
        $data = array(                
            'example_column_name' => $example,
        );
        $this->insert($data);            
    }