Is there a way to add some properties dynamically to a model?
Let's say I have a field called "strName" in my model, and this should be "splitted" into "strNameDe" and "strNameEn" for translation. The fields "strNameDe" and "strNameEn" doesn't exist in the model, they are stored into another table.
By now, I've have to declare:
public function rules()
array('strNameDe, strNameEn', 'required'),
I have also to add the following function to my model:
public function safeAttributes()
return CArray::merge($this->attributeNames(), array('strNameDe', 'strNameEn'));
Otherwise I will get an error, that these two fields doesn't exist in my model.
I want this to have more dynamically, because this might handy for only 1 field, but if I have 5 or more fields, this gets a bit nervy. I'm thinking about how this could be handled by defining an array, containing all the fields, which are multilingual like:
public $arrFieldTranslation = array('strName', 'strTitle', 'strText');
but I don't know how to get the following properties (without setting them by hand):
I have a lot of models, with a lot of fields to be mulitlingual, and I urgently need a solution.
I have a behavior which stores and loads the translated values, and everthing works fine by now, but I want to get this stuff more dynamic, because if I want to define a third language, I have to go through all of my models, and make the changes.
Is there a way, to add the properties dynamically, or the tell Yii, not to throw an error if these fields are not declared in the model?