First of all, thanks for this wonderful framework, it was the first one I could grasp and use it to cover my needs.
I am having trouble creating a complex model. I created a model to receive input from the user and I will have to call a web service and send a response back to the user. All is working well but I have 3 fields that can be repeated 'n' number of times, and I have to convert these fields to a specific string format required by the web service.
I couldn't find any example of a model with array fields and create 3 additional models just to use tabular input seems a little bit too complex (and verbose) for what I need.
How would be the correct way to handle this? I used jquery relCopy plugin to take care of field replication and it does exactly what I need but I am having trouble collecting the user input to make the conversion and calling the web service correctly afterwards.
If you need any additional info, feel free to ask.
Thanks in advance,
You could just serialize it into a TEXT field in your model.
That’s probably the best approach.
Just use the regular php serialize function.
Thanks for the answer.
While I understand what you are suggesting, simply using regular php I end up losing the "Yii way" of doing things. I need to do this without losing ajax data validation, error handling and all the good things Yii does for you and still deliver the data to the model without too much manual labor.
If I have to this manually, I will stick to the ugly copied and pasted field replication I am using today (which I know sucks and limits the final user a lot.
You could create a model for those three fields, of course.
Either a full on active record, or a form model.
Both will provide full validation, etc. what you expect from models.
Then set the relationship as HAS_MANY.
Maybe I’m getting this from the wrong perspective, but as I stated in the original thread, it seems kinda hard to have to create 3 models in HAS_MANY relationship and use tabular input just to create 3 simple string fields.
There is no database representation of this model, so I shouldn’t have a complex model to solve such a simple problem in an elegant way.
Can’t I just define an array field in the model and in some way tie this to the view in a simpler manner?
We are both getting it from the wrong perspective here I guess.
Yes, you can.
No matter what kind of model you’re using.
You can also use validation rules for those ‘fields’.
And that you are not using an active record model makes it even easier.
Why didn’t you say so from the start?