Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP newbie question: How to add non-database attribute to model?

Tags:

cakephp

I want to create a model that has SOME attributes that are not stored in a database. For example, I want to maintain an "age" field in the model, but I only store birthday information in the database (I can calculate "age" once the DOB info has been loaded). I tried adding a simple attribute to a model extension, but as far as I can tell, it's ignored by CakePHP. What's the proper way to go about accomplishing this?

I'm a CakePHP novice, so forgive me if I'm missing something obvious.

like image 572
Steve Avatar asked Dec 14 '22 02:12

Steve


1 Answers

I'd do it using the afterFind callback method in the model.

like image 113
Marko Avatar answered Mar 30 '23 01:03

Marko