Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3843620
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:57:50+00:00 2026-05-19T15:57:50+00:00

Extended Question: Why should I use data mapper / Db_Table_Row, where as DbTable is

  • 0

Extended Question: Why should I use data mapper / Db_Table_Row, where as DbTable is capable of handling most of the basic tasks for data manipulation.

I am currently learning ZF v1.11

For Database manipulation, I created DbTable for each tables. For example, “users” table is represented by Application_Model_DbTable_Users with no additional codes in there.

When manipulating data, I can use:

<?php
$uTable = new Application_Model_DbTable_Users();
$newUid = $uTable->insert(array('name'=>'Old Name', 'email'=>''));
$user = $uTable->find($newUid)->current();

// Then I can use $user which is instance of Table_Row
$user->name = "New Name";
$user->email = "email@addr.com";
$user->save();

My Question is, when would I need to define a row class (assuming Table_Row is referred as DataMapper in ZF-Tutorials)

// By, adding this to the DbTable class
protected $_rowClass = 'Application_Model_User';

What are the benefits of having a Row class for each entity? Can anyone point me to best practices for this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T15:57:51+00:00Added an answer on May 19, 2026 at 3:57 pm

    You do not need to define your own Table_Row. However, it maybe useful in many cases, particularly if you want to define some specific methods or properties for a given user row. They can also improve readability of your code.

    For example in your Users table case, you could define a method called getFullName() in a custom user row as:

    public function getFullName() {
        return $this->firstName . ' ' . $this->lastName;
    }
    

    Then when you obtain user row object, to get the full name of the user, you just do:

    $user = $uTable->find($newUid)->current();
    $fullName = $user->getFullName();
    

    Second example is when you have some parent table to the Users table, such as Addresses. In this case you could define a method called getAddress in a user row:

    public function getAddress() {
        return $this->findParentRow('Application_Model_DbTable_Addresses');
    }
    

    In this scenario, you would get an Address row object for a current user as follows:

    $user = $uTable->find($newUid)->current();
    $addressRow = $user->getAddress();
    

    Another example, would be when you want to create custom delete or instert methods. Lets assume that you want to make sure you do not want to delete an admin user using delete() method. Then you could overload delete method from Zend_Db_Table_Row as follows:

    public function delete() {
            if ('admin' === $this->userRole) {
                  return 0;
            }
            return parent::delete();
    } 
    

    This way, you would not be able to delete an admin user just by calling delete() on a user row object:

     $user = $uTable->find($newUid)->current();
     $rowsDeleted = $user->delete(); // would be 0 if $user is admin
    

    These are just three basic examples showing usefulness of defining your own row classes. But of course they are not necessary. However, from my own experience they are quite handy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can jQuery be extended so that I can use the above syntax? I can't
I'm currently adding some new extended classes to this code: foreach (BaseType b in
Extended Backus–Naur Form: EBNF I'm very new to parsing concepts. Where can I get
What is the equivalent of the extended procedure 'xp_dirscan' in SQL Server 2005?
I have a SharePoint site extended for forms authentication. The Active Directory site is
I've set up FBA on an extended site, added a user, verified the central
I am working on a project that is built on an extended version of
I know of the following: The venerable getopt(3) The extended getopt_long glibc's argp parser
Is there a way to write an enumeration that can be extended. I have
I have a C++ Windows application that can be extended by writing C++ plugins,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.