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

  • SEARCH
  • Home
  • 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 4091128
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:19:37+00:00 2026-05-20T19:19:37+00:00

Imagine I have a table called item that has a column called price. In

  • 0

Imagine I have a table called “item” that has a column called “price”. In addition to the full price, I’d like to get the price spread across 12 months, i.e.,

class Item extends Doctrine_Record {
  ...
  public function getMonthlyPrice() {
    return $this->price/12;
  }
}

Now, say I’d like to have Item act like the monthly price is just another column rather than a function call, e.g.,

$m = Doctrine_Core::getTable("Item")->find(1);
echo $m->price; //prints 120
echo $m->monthlyPrice; //prints 10

My first instinct is to override the __get() method. Is there a better or more standard way to do this in Doctrine?


Bonus question:

Is there some very clever way I can rig the object so when I do

var_dump($m->getData())

I see

array
  'price' => 120
  'monthlyPrice' => 10

That would be pretty nifty.

  • 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-20T19:19:38+00:00Added an answer on May 20, 2026 at 7:19 pm

    As Brian said you could do this with filters, but there is another way which I think is closer to what you’re looking for – you’d need to enable Doctrine’s ATTR_AUTO_ACCESSOR_OVERRIDE feature, which means that it will check for methods in the form get* and set* which match your property call them automatically. Here’s an example:

    class Example extends Doctrine_Record {
    
        public function getFoo() {
            return 'foo';
        }
    }
    
    Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
    
    $example = new Example();
    echo $example->foo;
    

    As to the second part of your question, not that I’ve seen – your best bet is to override the method in your models as appropriate, or create a subclass of Doctrine_Record that your models then extend which has a single override that wraps up that functionality.

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

Sidebar

Related Questions

Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this
I have a problem. Imagine this data model: [Person] table has: PersonId, Name1 [Tag]
Imagine I have the following data in a table called messages: message_id | language_id
2 databases QF AND TK QF has the following: Imagine you have a table
imagine I have this table called Department. Each Department can have child Departments. I
hi there imagine I have a table like this Id | Name | City
Imagine I have a process that starts several child processes. The parent needs to
Imagine I have a property defined in global.asax. public List<string> Roles { get {
Here is the scenario 1. I have a table called items, inside the table
I have a table called wp-posts with a field post-content. This field contains the

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.