Answers.Body: <p>I think you're out of luck.  You can't go through the magic <code>__get()</code> logic and have a concrete <code>get</code> method and use both.  How will Yii/PHP know which one you're referring to when you do <code>$model-&gt;fullName</code>?</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-14T03:16:09.050Z
Answers.Text: Ok, I thought that might be the case.
Answers.UserDisplayName: Tim Kelty
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-14T03:24:44.113Z
Answers.Text: I don't necessarily need it in both places, I just need a way to get the populated model, including `fullName`, without having to manually add it every time.
Answers.UserDisplayName: Tim Kelty
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-14T03:28:41.403Z
Answers.Text: Not sure I'm following that 100%. Maybe a case for a behavior ? (http://www.yiiframework.com/wiki/44/behaviors-events/)
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-14T03:30:10.553Z
Answers.Text: A behavior in Yii is similar to a Ruby mixin or PHP trait if you're familiar with those.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-14T15:03:07.173Z
Answers.Text: I'll look at behaviors, thanks. Here's the real example of what I'm trying to do: https://gist.github.com/timkelty/09b42e50105b6c420c5b
Answers.UserDisplayName: Tim Kelty
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-14T15:51:50.857Z
Answers.Text: Ah duh...is it just a matter of overriding the populateModel method in my model? Does that also get called with `new MyModel()`, or should I override the constructor?
Answers.UserDisplayName: Tim Kelty
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-14T17:59:04.347Z
Answers.Text: You'll probably want to override the constructor.  Just be sure and call `parent::__construct()`, too.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-13T23:37:44.163Z
Answers.LastActivityDate: 2014-11-13T23:37:44.163Z
Answers.UserDisplayName: Brad Bell
Body: <p>Take the <a href="http://www.yiiframework.com/wiki/167/understanding-virtual-attributes-and-get-set-methods" rel="nofollow">example</a> of a model with a <code>firstName</code> and <code>lastName</code>.</p>
  
  <p>I know I can add a <code>getFullName</code> method to the model, and <code>$model-&gt;fullName</code> will run through the getter.</p>
  
  <p>However, I'd like the attribute to also remain part of the model (accessible through $model->attributes), which if I use the getter, it isn't.</p>
  
  <p>If I use the getter AND include the same name in <code>defineAttributes</code>, the getter is ignored.</p>
  
  <p>Is there a way to achieve this?</p>
  
Tags: <plugin-development><models><attribute>
Title: How can I have a dynamic/virtual attribute AND have as an attribute of the Model?
ThreadText: # How can I have a dynamic/virtual attribute AND have as an attribute of the Model?
  
  (Asked by: username_0 on 2014-11-13)
  
  Take the [example](http://www.yiiframework.com/wiki/167/understanding-virtual-attributes-and-get-set-methods) of a model with a `firstName` and `lastName`.
  
  I know I can add a `getFullName` method to the model, and `$model->fullName` will run through the getter.
  
  However, I'd like the attribute to also remain part of the model (accessible through $model->attributes), which if I use the getter, it isn't.
  
  If I use the getter AND include the same name in `defineAttributes`, the getter is ignored.
  
  Is there a way to achieve this?
  
  **Tags:** plugin-development, models, attribute
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-11-13. Score: 0 | Accepted answer
  
  I think you're out of luck. You can't go through the magic `__get()` logic and have a concrete `get` method and use both. How will Yii/PHP know which one you're referring to when you do `$model->fullName`?
  
  > **Comments:**
  > **username_0**: Ok, I thought that might be the case.  
  > **username_0**: I don't necessarily need it in both places, I just need a way to get the populated model, including `fullName`, without having to manually add it every time.  
  > **username_1**: Not sure I'm following that 100%. Maybe a case for a behavior ? (http://www.yiiframework.com/wiki/44/behaviors-events/)  
  > **username_1**: A behavior in Yii is similar to a Ruby mixin or PHP trait if you're familiar with those.  
  > **username_0**: I'll look at behaviors, thanks. Here's the real example of what I'm trying to do: https://gist.github.com/username_0/09b42e50105b6c420c5b  
  > **username_0**: Ah duh...is it just a matter of overriding the populateModel method in my model? Does that also get called with `new MyModel()`, or should I override the constructor?  
  > **username_1**: You'll probably want to override the constructor.  Just be sure and call `parent::__construct()`, too.  
  
  ---
  
  