How I can embed some form, for example, based on some Option model entity to another form, based on Product entity?
|
Feb '15 |
5 |
1423 |
1 |
How I can embed some form, for example, based on some Option model entity to another form, based on Product entity?
I'm about something else. Okay, try to describe another example. I have model named <News>, it has only <id> and <created> field. And i have model named like <NewsTranslation>, which contains multilanguage field, such as <title>, <description>, <content> etc. Question: Can I embed <NewsTranslation> as sub-form into <News> form for further processing as <News> object with embedded relations? The result that I want to get, something like this:
$news = new News();
$news->created = '2013-06-17';
$news->translation['en']->title = 'My Title';
$news->translation['en']->description = 'My Description';
$news->translation['de']->title = 'Meine Titel';
$news->translation['de']->description = 'Meine Beschreibung';
this chapter https://symfony.com/legacy/doc/jobeet/1_4/en/19?orm=Doctrine#chapter_19_sub_admin_generator describes what i mean
Yes, there are two ways (I can think of):
$news->getTranslation(" lang = 'en' ")->title
(the bad part: you will have a lot more queries)
You choose which is best for you.
Ok but how will you represent the data in the view? If $sub1 and $sub2 are two separate forms you can create them as explained here: https://docs.phalcon.io/en/latest/reference/forms.html (by the way in HTML you cannot have subforms - one form inside of the other)
What Dmitry Korniychuk is asking for is this kind of behavior:
$sub1 = $form->addContainer('first');
$sub1->addText('name[]', 'Your name:');
$sub1->addText('email[]', 'Email:');
$sub2 = $form->addContainer('second');
$sub2->addText('name[]', 'Your name:');
$sub2->addText('email[]', 'Email:');
This will allow you to create via javascript new form set, validate it where name(first) and name(second) are tereated as different elements, and submit the form, which will result in two database row entries. Unfortunately so far i cannot find solution in phalconphp framework but this is definitely a real life scenario, so if any one can help, pelase you are welcome!