Forms and their sub models

Hey everyone again,

I have what will most likely be a simple question. Does yii handle sub models within parent forms?

I have a single form which should be one form. Within this form I have the parent model (say title) and a sub model (say geozone).

Is there a way with using the with() command on the AR to use this sub model within the parent form and have the title model know that the sub part of the form is to the geozone model?

I thought this would be done through the attribute name like so:

$form->textField($model, "geozone[id]")

But then I wondered what if I had a field that I wanted to come in as an array like so:

$form->textField($model, "geozone[id][]")

In practical sense that should tell yii that it is a sub model list field, right?

Does yii handle the way I think it does or am I just dreaming? :)

Thanks in advance

i think you are looking for something like this:

Not able to understand your problem properly…

I had used a single form and stored values in different models.

So i think you can go through this topic and see if u got ur answer"

Thanks for all your replies.

The link @Mursi gave over helped a lot. I must not have seen that little bit at the bottom with the forms on Friday.

Just one more question what if the second part of my document is not a model in itself but more of a relationship. How can I validate and write it back within the model?

So I have the relationship fully set up between a title and many geozones with a lookup table called title_geozones. It would be a waste to make it its own model so it is a relationship within the title model and ofc I pick it out via $title->geozones->whatever.

What’s the documentation for writing using that relationship?


Found it now in tabular input.

I was just being my blind old self.