Model with database data and non-database data as attributes

Short Question:

Is is possible to have non-database data retrieved as an attribute of an Active Record just as if it were stored in the database?

Long Question:

Let’s say we are storing first name and last name in the database but I also want to access a full name attribute just as easily. The example is I want to be able to do this:




$user = User::findOne(--id goes here--);

echo $user->first_name;

echo $user->last_name;

echo $user->full_name;



For all intents and purposes, I want every bit of my application to believe full_name to be a field in the database (when read, it creates the value, when written-to it performs some other logic, perhaps setting other data based on its value). It looks like I can write a getFullName() function but then it is not available when I do the following:




$user->getAttributes())



or the this in a beforeSave function




$audit = new Audit();

$audit->previous_values = Json::encode($this->getOldAttributes());

$audit->save();



So, how can I create a "virtual" attribute that acts just as if it were another field in the table without actually storing it in the table. Data reads will return a dynamic value I create on the fly and writes will perform some other logic such as writing to multiple fields)