While we're talking implementations, I thought I'd chime in with how I
solved this problem).

My implementation was for editing Translations (I may post about my
i18n implementation in another topic soon enough). One example
specifically is for a user's first and last name (if I'm posting a
message on the Chinese message board of the site, I want my Chinese
name to show up, but if I'm on the English side, I want my English
name). Anyway, a user shouldn't have to go to a complicated separate
page to enter their name in when signing up. The name as usual consists
of 2 fields -- firstname and lastname

I wanted to keep use of the TranslationModel for doing auto error
checking, and so I could continue to use the HTML helper for creating
form inputs, outputing errors, and filling in existing values for the
name inputs, so rather than doing everything manually, I kind of hacked
things a bit.

When the page is displayed a helper outputs a set of inputs for each of
firstname and lastname. The inputs are the visible 'value' text field
as well as various hidden fields for specifying what language it's in,
etc. In the view this is accomplished with a simple 1 line call to the
helper function. Each set of inputs is given it's own enumerated 'fake'
model name, such as  Translation1, Translation2, etc.

When data is submitted, a TranslateComponent is used to check the
submitted data array for models matching "Translation#". When it finds
them, it creates a new instances of the TranslationModel, and adds them
to the controller's array of models in $this->modelNames (this is
needed so that the validationErrors array for these fake models are
properly merged and outputted to the view, since Model->render() uses
this array for that).

Upon successful validation of the TranslationModel's and other data,
the translations need to be saved (there are 2 separate saves, so
validation must be validated manually, not just automatically during
the Model->save() call). Another TranslateComponent function steps in
to do this, by executing a loop like Mike wrote about above (and yes,
don't forget the create() call!), to save each of the found 'fake'
models.

If something doesn't validate, then you don't have to do anything-- the
view helper ensures that the error messages and existing values are
properly displayed thanks to the inputs' naming.

The only problem with this is that when I go to save the 2
newly-created translation id's into my User Object, I then have to make
an assumption, that the 1st set of inputs (Translation1) is the first
name, and the second (Translation2) is the last name. Swapping these in
the view will mix things up, so it violates the MVC principle a bit.

I enjoyed reading the other solution provided, and would love to hear
about how others are doing this, I have another similar situation that
I haven't coded yet that will be even more complicated, so if there's
some better solution, it's not too late to save me from the clutches of
my own ignorance!

Cheers.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to