|"fake" properties on models [message #103339]
||Sat, 31 July 2010 09:15
Registered: July 2010
I'm sure there's a way of doing this, I just don't know a good way to search for it so I haven't found anything:|
I'd like to have a class that is done in a way that all instances of it have a property that isn't necessarily in the database, but is added after instantiation so that it's always available for the actions and views to use.
In this way, I'd like all instances of my Category class to have a $category->slug property that is dynamically created by slug-ifying the name of each category.
$cat = CategoryTable::findByName('Track Jackets');
... executed somewhere ...
$this->slug = preg_replace('/[^a-z]+/', '-', strtolower($this->name));
echo $cat->slug; // 'track-jackets'
Is this a filter? What can I use for this?
Thanks for any tips,
[Updated on: Sat, 31 July 2010 09:17]