Creating i18n forms with only some fields from table isn't possible so
I give You my idea :)

I have schema.yml:
Firm:
  actAs:
    I18n:
      fields: [description, address]
  columns:
    id_firm:
      type: integer(1)
      primary: true
      autoincrement: true
    email:
      type: string(100)
      notnull: true
    description:
      type: clob
      notnull: true
    address:
      type: clob

I would like to create first form with only fields 'email' from table
Firm and 'address' from table Firm_translation (without field
'description') so we must create action for example for edit in which
we get information about firm and pass it to the form, after submit we
take values from the form and save it:
  public function executeEdit_contact(sfWebRequest $request)
  {
        $firma = Doctrine::getTable('Firm')->find($this->id_firm);

        $this->form = new ContactForm(null, array('firm' => $firm));
        if ($request->isMethod('post'))
       {
            $this->form->bind($request->getParameter($this->form->getName
()));
            if ($this->form->isValid())
            {
                $email = $this->form->getValue('email');
                $contact_pl = $this->form->getValue('contact_pl');
                $contact_en = $this->form->getValue('contact_en');

                
Doctrine::getTable('Firm')->actualizationContactFirm($this->id_firm,
$email, $contact_pl, $contact_en);
            }
        }
  }


Next create 2 fields per one i18n field - example:
class ContactForm extends sfForm
{
  public function configure()
  {
        $this->widgetSchema['email'] = new sfWidgetFormInput();
        $this->widgetSchema['contact_pl'] = new sfWidgetFormTextarea();
        $this->widgetSchema['contact_en'] = new sfWidgetFormTextarea();

        $firma = $this->getOption("firm"); //get array from the action

        $this->setDefault('email', $firm['email']);
        $this->setDefault('contact_pl', $firm['Translation']['pl']
['contact']);
        $this->setDefault('contact_en', $firm['Translation']['en']
['contact']);

        $this->setValidators(array(
          'email' => new sfValidatorEmail(array('max_length' => 100, 'trim'
=> true)),

          'contact_pl' => new sfValidatorString(array('min_length' =>
5, 'max_length' => 1000000, 'trim' => true)),

          'contact_en' => new sfValidatorString(array('min_length' => 5,
'max_length' => 1000000, 'trim' => true)),
        ));

        $this->widgetSchema['contactt_pl']->setAttribute('rows', 20);
        $this->widgetSchema['contact_pl']->setAttribute('cols', 70);

        $this->widgetSchema['contact_en']->setAttribute('rows', 20);
        $this->widgetSchema['contact_en']->setAttribute('cols', 70);

        $this->widgetSchema->setNameFormat('data[%s]');
  }
}


And queries:
class FirmTable extends Doctrine_Table
{
  public function actualizationContactFirm($id_firm, $email,
$contact_pl, $contact_en)
  {
        Doctrine_Query::create()
          ->update('Firm')
          ->set('email', '?', $email)
          ->where('id_firm = ?', $id_firm)
          ->execute();

        Doctrine_Query::create()
          ->update('FirmTranslation')
          ->set('contact', '?', $contact_pl)
          ->where('lang = ?', 'pl')
          ->andWhere('id_firm = ?', $id_firm)
          ->execute();

        Doctrine_Query::create()
          ->update('FirmTranslation')
          ->set('contact', '?', $contact_en)
          ->where('lang = ?', 'en')
          ->andWhere('id_firm = ?', $id_firm)
          ->execute();
  }
}


I think this is the best solution, unfortunately we have many repeat
code but I think we can't write it easier:(
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to