简体   繁体   中英

Zend Framework Model

is it posible to have a true Model Layer in PHP like in Ruby on Rails? With Zend Framework you can create a Model but this is a class. As I know you have to write all the logic by myself.

Solutions?

True, in Zend Framework you need to declare classes for the database tables you'd like to access. But the rest can be done implicitly, if the default behavious is sufficient. The following is a valid and functional model class (compare to http://framework.zend.com/manual/en/zend.db.table.html#zend.db.table.introduction ):

class bugs extends Zend_Db_Table_Abstract
{
    // table name matches class name
}

This should let you access the table named "bugs", eg:

$table = new bugs();
$data = array(
    'created_on'      => '2007-03-22',
    'bug_description' => 'Something wrong',
    'bug_status'      => 'NEW'
);
$table->insert($data);

Again, the example was taken directly from the documentation mentioned above.

或者从1.8.x开始,有一个用于模型的DataMapper模式(参见手册中的快速入门)

i wrote a script that might suite your needs.

http://code.google.com/p/zend-db-model-generator/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM