<legend id='NvKG9'><style id='NvKG9'><dir id='NvKG9'><q id='NvKG9'></q></dir></style></legend>
  • <i id='NvKG9'><tr id='NvKG9'><dt id='NvKG9'><q id='NvKG9'><span id='NvKG9'><b id='NvKG9'><form id='NvKG9'><ins id='NvKG9'></ins><ul id='NvKG9'></ul><sub id='NvKG9'></sub></form><legend id='NvKG9'></legend><bdo id='NvKG9'><pre id='NvKG9'><center id='NvKG9'></center></pre></bdo></b><th id='NvKG9'></th></span></q></dt></tr></i><div id='NvKG9'><tfoot id='NvKG9'></tfoot><dl id='NvKG9'><fieldset id='NvKG9'></fieldset></dl></div>

    <small id='NvKG9'></small><noframes id='NvKG9'>

        <tfoot id='NvKG9'></tfoot>

        • <bdo id='NvKG9'></bdo><ul id='NvKG9'></ul>

        在 Zend Framework 中为具有多个表关系的对象建模

        时间:2023-10-03
          <bdo id='kYqAW'></bdo><ul id='kYqAW'></ul>

            <small id='kYqAW'></small><noframes id='kYqAW'>

          • <tfoot id='kYqAW'></tfoot>

            <legend id='kYqAW'><style id='kYqAW'><dir id='kYqAW'><q id='kYqAW'></q></dir></style></legend>
              <tbody id='kYqAW'></tbody>

                  <i id='kYqAW'><tr id='kYqAW'><dt id='kYqAW'><q id='kYqAW'><span id='kYqAW'><b id='kYqAW'><form id='kYqAW'><ins id='kYqAW'></ins><ul id='kYqAW'></ul><sub id='kYqAW'></sub></form><legend id='kYqAW'></legend><bdo id='kYqAW'><pre id='kYqAW'><center id='kYqAW'></center></pre></bdo></b><th id='kYqAW'></th></span></q></dt></tr></i><div id='kYqAW'><tfoot id='kYqAW'></tfoot><dl id='kYqAW'><fieldset id='kYqAW'></fieldset></dl></div>

                  本文介绍了在 Zend Framework 中为具有多个表关系的对象建模的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试使用 Zend Framework,并尝试针对我正在制作的网站使用快速入门"指南,只是为了了解该过程将如何运作.如果这个答案很明显,请原谅我,希望有经验的人可以对此有所了解.

                  I'm toying with Zend Framework and trying to use the "QuickStart" guide against a website I'm making just to see how the process would work. Forgive me if this answer is obvious, hopefully someone experienced can shed some light on this.

                  我有三个数据库表:

                  CREATE TABLE `users` (
                    `id` int(11) NOT NULL auto_increment,
                    `email` varchar(255) NOT NULL,
                    `username` varchar(255) NOT NULL default '',
                    `first` varchar(128) NOT NULL default '',
                    `last` varchar(128) NOT NULL default '',
                    `gender` enum('M','F') default NULL,
                    `birthyear` year(4) default NULL,
                    `postal` varchar(16) default NULL,
                    `auth_method` enum('Default','OpenID','Facebook','Disabled') NOT NULL default 'Default',
                    PRIMARY KEY  (`id`),
                    UNIQUE KEY `email` (`email`),
                    UNIQUE KEY `username` (`username`)
                  ) ENGINE=MyISAM DEFAULT CHARSET=latin1
                  
                  CREATE TABLE `user_password` (
                    `user_id` int(11) NOT NULL,
                    `password` varchar(16) NOT NULL default '',
                    PRIMARY KEY  (`user_id`),
                    UNIQUE KEY `user_id` (`user_id`)
                  ) ENGINE=MyISAM DEFAULT CHARSET=latin1
                  
                  CREATE TABLE `user_metadata` (
                    `user_id` int(11) NOT NULL default '0',
                    `signup_date` datetime default NULL,
                    `signup_ip` varchar(15) default NULL,
                    `last_login_date` datetime default NULL,
                    `last_login_ip` varchar(15) default NULL,
                    PRIMARY KEY  (`user_id`),
                    UNIQUE KEY `user_id` (`user_id`)
                  ) ENGINE=MyISAM DEFAULT CHARSET=latin1
                  

                  我想创建一个在某些情况下使用所有三个表的用户模型.例如,如果/当需要元数据时访问元数据表.仅当设置了默认"auth_method 时才访问 user_password 表.稍后我可能会添加一个配置文件表,我希望能够从用户模型访问该表.

                  I want to create a User model that uses all three tables in certain situations. E.g., the metadata table is accessed if/when the meta data is needed. The user_password table is accessed only if the 'Default' auth_method is set. I'll likely be adding a profile table later on that I would like to be able to access from the user model.

                  使用采埃孚做到这一点的最佳方法是什么?为什么?

                  What is the best way to do this with ZF and why?

                  推荐答案

                  class Users extends Zend_Db_Table_Abstract
                  {
                      protected $_name = 'users';
                      protected $_rowClass = 'User';
                      protected $_dependentTables = array ('UserMetadata', 'UserPassword');
                  
                  ...
                  
                  class UserMetadata extends Zend_Db_Table_Abstract
                  {
                      protected $_name = 'user_metadata';
                      protected $_referenceMap = array (
                      'Users'=> array (
                      'columns'=>'user_id',
                      'refTableClass'=>'Users',
                      'refColumns'=>'id'
                      )
                      );
                  
                  ...
                  
                  class UserPassword extends Zend_Db_Table_Abstract
                  {
                      protected $_name = 'user_password';
                      protected $_referenceMap = array (
                      'Users'=> array (
                      'columns'=>'user_id',
                      'refTableClass'=>'Users',
                      'refColumns'=>'id'
                      )
                      );
                  

                  获取数据:

                  $id = //get your user id from somewhere
                  
                  $users = new Users();
                  $user = $users->fetchRow('id=?', $id);
                  if ($user->authMethod == 0)
                  {
                      $metadata = $user->findDependentRowset('UserMetadata')->current();
                  }
                  

                  $user = $users->fetchRow($users->select()
                                ->where('gender=?, 'M')
                                ->order('email ASC');
                  

                  ...等

                  插入数据:

                  $newRow = $users->fetchNew();
                  $newRow->email = me@domain.com;
                  $newRow->save();
                  

                  $users = new Users();
                  $data = array('email'     => 'me@domain.com',
                                'firstname' => 'Me');
                  $users->insert($data);
                  

                  更新:

                  $user->email = 'me@domain.org';
                  $user->save();
                  

                  删除一行:

                  $user->delete();
                  

                  使用交易:

                  $db->beginTransaction();
                  $db->commit();
                  $db->rollback();
                  

                  等等...都在 ZF 手册中!

                  这篇关于在 Zend Framework 中为具有多个表关系的对象建模的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何添加视图助手目录(zend 框架) 下一篇:PHP中的两个冒号是什么意思?

                  相关文章

                  最新文章

                  <small id='hDGIA'></small><noframes id='hDGIA'>

                  <tfoot id='hDGIA'></tfoot>
                1. <i id='hDGIA'><tr id='hDGIA'><dt id='hDGIA'><q id='hDGIA'><span id='hDGIA'><b id='hDGIA'><form id='hDGIA'><ins id='hDGIA'></ins><ul id='hDGIA'></ul><sub id='hDGIA'></sub></form><legend id='hDGIA'></legend><bdo id='hDGIA'><pre id='hDGIA'><center id='hDGIA'></center></pre></bdo></b><th id='hDGIA'></th></span></q></dt></tr></i><div id='hDGIA'><tfoot id='hDGIA'></tfoot><dl id='hDGIA'><fieldset id='hDGIA'></fieldset></dl></div>

                      • <bdo id='hDGIA'></bdo><ul id='hDGIA'></ul>
                      <legend id='hDGIA'><style id='hDGIA'><dir id='hDGIA'><q id='hDGIA'></q></dir></style></legend>