This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » symfony 1.3 and 1.4 » "fake" properties on models
"fake" properties on models [message #103339] Sat, 31 July 2010 09:15 Go to next message
jfeldstein  is currently offline jfeldstein
Messages: 2
Registered: July 2010
Junior Member
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.

Something like:

$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,
~J

[Updated on: Sat, 31 July 2010 09:17]

Re: "fake" properties on models [message #103342 is a reply to message #103339 ] Sat, 31 July 2010 09:45 Go to previous messageGo to next message
letbeserious  is currently offline letbeserious
Messages: 97
Registered: May 2007
Member
this is a Category model, just add needed methods there
Re: "fake" properties on models [message #103378 is a reply to message #103339 ] Sun, 01 August 2010 19:55 Go to previous messageGo to next message
halfer  is currently offline halfer
Messages: 9535
Registered: January 2006
Location: West Midlands, UK
Faithful Member
Are you using Propel or Doctrine?


Remember Palestine
Re: "fake" properties on models [message #103389 is a reply to message #103339 ] Mon, 02 August 2010 07:12 Go to previous message
jfeldstein  is currently offline jfeldstein
Messages: 2
Registered: July 2010
Junior Member
Doctrine, I'm going to try playing with this tomorrow: http://www.symfony-project.org/jobeet/1_2/Doctrine/en/07
Previous Topic:┬┐The best way to add new locale properties with i18n? (sfCultureInfo)
Next Topic:Dynamically Adding a new Form Element
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software