Hello,
This is a quick example. Please note the updateObject method is to fix
an issue with doctrine.
class ParentForm extends BaseParentForm
{
public function setup()
{
parent::setup();
$this->embedForm('ChildObject', new
ChildObjectForm($this->getObject()->getChildObject()));
}
public function configure()
{
$this->widgetSchema['category_id']->setOption('add_empty', false);
}
public function updateObject()
{
$object = parent::updateObject();
$this->getObject()->ChildObject->Parent = $this->getObject();
return $object;
}
}
On Wed, Oct 8, 2008 at 10:31 AM, Alex <[EMAIL PROTECTED]> wrote:
>
> Thanks for fast reply, Thomas! This is very helpful.
>
> I use Doctrine. Do you have any example of form?
>
> On Oct 8, 11:52 am, "Thomas Rabaix" <[EMAIL PROTECTED]> wrote:
>> Hello,
>>
>> 1. Clean form :
>> You should create a new class which extends the default signup form.
>> In this class you create the embed form (the setup method) and
>> overwrite the save method. So mainly you move your logic from the
>> action to the new form.
>>
>> 2. Propel vs Doctrine :
>> Now doctrine implements an array interface, that's means when you bind
>> values from the request, the value are cascadly (?) defined to related
>> object. Propel does not have this feature, so I suppose you have to do
>> that by hand in the save method. You can use the model::fromArray
>> method or recreate a form (which isnot great IMHO)
>>
>> Thomas
>>
>>
>>
>> On Tue, Oct 7, 2008 at 9:50 PM, Alex <[EMAIL PROTECTED]> wrote:
>>
>> > Hi, all. I think i did not understand this embed form system, so i
>> > need some help...
>>
>> > Pretty usual example is registration form.
>> > I have two tables sf_guard_user and sf_guard_user_profile and two
>> > forms.
>>
>> > This is usual forms with all necessary widgets and validators.
>>
>> > This is my sing up action:
>>
>> > public function executeIndex($request)
>> > {
>>
>> > $singupForm = new SingupUserForm();
>> > $userProfileForm = new SingupUserProfileForm();
>>
>> > $singupForm->embedForm('Profile', $userProfileForm);
>>
>> > $this->singupForm = $singupForm;
>>
>> > if ($request->isMethod('post'))
>> > {
>> > $singupData = $request->getParameter('singup');
>>
>> > $singupData['username'] = $singupData['email']; // don`t think
>> > about it
>> > $singupData['algorithm'] = 'sha1'; // and about it too ;)
>>
>> > $this->singupForm->bind($singupData);
>>
>> > if($this->singupForm->isValid()){
>> > $newUserId = $this->singupForm->save();
>>
>> > $newUserProfileFrom = new SingupUserProfileForm();
>>
>> > $newUserProfileData = $singupData['Profile'];
>> > $newUserProfileData['user_id'] = $newUserId->id;
>> > $newUserProfileFrom->bind($newUserProfileData);
>> > $newUserProfileFrom->save();
>> > //$this->redirect('singup/thankyou');
>> > }
>> > }
>>
>> > this works fine and i got records in both tables, BUT if a cant just
>> > do $this->singupForm->save(); and get all things done... i think i do
>> > something wrong...
>> > and this piece of code makes 4 queries to database!!! i don`t need
>> > this at all;)
>>
>> > i can still use something like that (it works great):
>>
>> > $newUser = new sfGuardUser();
>> > $newUser->email = '[EMAIL PROTECTED]';
>>
>> > $newUserProfile = new sfGuardUserProfile();
>> > $newUserProfile->first_name = 'alex';
>> > $newUser->setProfile($newUserProfile);
>> > $newUser->save();
>>
>> > but i believe there is a better way for forms.
>>
>> --
>> Thomas Rabaix
>> Internet Consultant
> >
>
--
Thomas Rabaix
Internet Consultant
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---