Witam,
Mam 2 formularze: CompanyForm i sfGuardUserForm. Company Form ma input do zapisywania zdjec. Odzielnie oba formularzedzialaja bezblednie. Problem w tym ze jak je polacze w jedem formularz, to dostaje ten blad: : Unknown record property / related component "Profil|company_logo" on "sfGuardUser"
Szukam juz caly dzien ale nie wiem jak to ugryzc.
Kod:
class RegisterForm extends BasesfGuardUserForm
{
public function configure()
{
$this->removeFields();
$this->widgetSchema['password'] = new sfWidgetFormInputPassword();
$this->widgetSchema['password_confirmation'] = new sfWidgetFormInputPassword();
$this->validatorSchema['username'] = new sfValidatorDoctrineUnique
(array('model' => 'sfGuardUser', 'column' => 'username'));
$this->widgetSchema->setLabels(array( 'password' => '<span class="important">*</span>Hasło',
'password_confirmation' => '<span class="important">*</span>Potwierdź hasło',
'username' => '<span class="important">*</span>Nick',
));
$this->setValidators(array(
'username' => new sfValidatorString
(array('min_length' => 6, 'required' => true), array('required' => 'To pole jest wymagane', 'min_length' => 'Nick jest za krótki.
Proszę podać minimalnie %min_length% znaków')),
'password' => new sfValidatorString
(array('min_length' => 6, 'required' => true), array('required' => 'To pole jest wymagane', 'min_length' => 'Hasło jest za krótkie.
Proszę podać minimalnie %min_length% znaków')),
'password_confirmation' => new sfValidatorString
(array('min_length' => 6, 'required' => true), array('required' => 'To pole jest wymagane', 'min_length' => 'Potwierdzenie hasła jest za krótkie.
Proszę podać minimalnie %min_length% znaków')),
));
$this->mergePostValidator(new sfValidatorSchemaCompare
('password', sfValidatorSchemaCompare
::EQUAL, 'password_confirmation', array(), array('invalid' => 'Hasło i potwierdzenie hasła muszą być takie same')));
$companyForm = new CompanyForm($this->object->Company);
//unset($companyForm['company_logo']);
$this->embedMergeForm('Profil', $companyForm);
}
protected function removeFields()
{
$this['is_active'],
$this['is_super_admin'],
$this['updated_at'],
$this['groups_list'],
$this['permissions_list'],
$this['last_login'],
$this['created_at'],
$this['salt'],
$this['algorithm']
);
}
}
<?php
class CompanyForm extends BaseCompanyForm
{
public function configure()
{
$this->removeFields();
$this->widgetSchema['company_logo'] = new sfWidgetFormInputFileEditable
(array( 'file_src' => '/'.basename(sfConfig
::get('sf_upload_dir')).'/company/thumb/'.$this->getObject()->getCompanyLogo(), 'is_image' => true,
'delete_label' => 'usuń aktualne logo',
'edit_mode' => strlen($this->getObject()->getCompanyLogo()) > 0, 'template' => '<div>%file% %input%<br/>%delete% %delete_label%</div>'
));
$this->validatorSchema['company_logo'] = new sfValidatorFile
(array( 'required' => false,
'mime_types' => 'web_images'
));
$this->widgetSchema->setLabels(array( 'first_name' => '<span class="important">*</span>Imię',
'last_name' => '<span class="important">*</span>Nazwisko',
'email' => '<span class="important">*</span>Adres e-mail',
'phone' => '<span class="important">*</span>Telefon',
'company_name' => '<span class="important">*</span>Nazwa Firmy',
'company_nip' => '<span class="important">*</span>NIP',
'company_regon' => '<span class="important">*</span>Regon',
'company_address' => '<span class="important">*</span>Ulica',
'company_city' => '<span class="important">*</span>Miasto',
'company_postcode' => '<span class="important">*</span>Kod pocztowy',
'company_logo' => 'Logo firmy',
));
$this->validatorSchema['company_logo_delete'] = new sfValidatorPass();
$this->validatorSchema['company_name'] = new sfValidatorString
(array('required' => true), array('required' => 'To pole jest wymagane'));
$this->validatorSchema['company_nip'] = new NipValidator
(array('required' => true), array('required' => 'To pole jest wymagane', 'invalid' => 'NIP jest niepoprawny'));
$this->validatorSchema['company_regon'] = new RegonValidator
(array('required' => true), array('required' => 'To pole jest wymagane', 'invalid' => 'Regon jest niepoprawny'));
$this->validatorSchema['company_address'] = new sfValidatorString
(array('required' => true), array('required' => 'To pole jest wymagane'));
$this->validatorSchema['company_city'] = new sfValidatorString
(array('required' => true), array('required' => 'To pole jest wymagane'));
$this->validatorSchema['company_postcode'] = new sfValidatorRegex(
array('pattern' => '/^[0-9]{2}-?[0-9]{3}$/', 'required' => true), array('invalid'=>'Nieprawidłowy kod pocztowy.', 'required' => 'To pole jest wymagane'));
$this->validatorSchema['first_name'] = new sfValidatorString
(array('required' => true), array('required' => 'To pole jest wymagane'));
$this->validatorSchema['last_name'] = new sfValidatorString
(array('required' => true), array('required' => 'To pole jest wymagane'));
$this->validatorSchema['phone'] = new sfValidatorString
(array('required' => true), array('required' => 'To pole jest wymagane'));
$this->validatorSchema['email'] = new sfValidatorEmail
(array('required' => true), array('invalid' => 'Adres e-mail jest niepoprawny', 'required' => 'To pole jest wymagane'));
}
protected function removeFields()
{
$this['slug'],
$this['id'],
$this['is_activated']);
}
public function updateObject()
{
$image = $this->getValue('company_logo');
$filename = $this->object->getCompanyLogo();
$file = sfConfig::get('sf_web_dir').'/uploads/company/'.$filename;
$thumb = sfConfig::get('sf_web_dir').'/uploads/company/thumb/'.$filename;
if ($image)
{
// remove old image
{
}
{
}
}
// update the product
parent::updateObject();
if ($image)
{
// save new image
$filename = sha1($image->getOriginalName()).$image->getExtension($image->getOriginalExtension());
$image->save(sfConfig::get('sf_web_dir').'/uploads/company/'.$filename);
$thumbnail = new sfThumbnail(300, 300);
$thumbnail->loadFile(sfConfig::get('sf_web_dir').'/uploads/company/'.$filename);
$thumbnail->save(sfConfig::get('sf_web_dir').'/uploads/company/'.$filename);
$thumbnail = new sfThumbnail(150, 150);
$thumbnail->loadFile(sfConfig::get('sf_web_dir').'/uploads/company/'.$filename);
$thumbnail->save(sfConfig::get('sf_web_dir').'/uploads/company/thumb/'.$filename);
}
if ( $this->getValue('company_logo_delete') )
{
}
$this->object->setCompanyLogo($filename);
}
}
<form action="
<?php echo url_for
('@register_confirm') ?>" method="POST">
<?php echo $form['_csrf_token']; ?> <?php echo $form->renderGlobalErrors() ?>
<table class='form_table'>
<tr><td colspan="2"><h2>Dane osobowe</h2></td></tr>
<?php echo $form['Profil|first_name']->renderRow(array('class' => 'input')) ?> <?php echo $form['Profil|last_name']->renderRow(array('class' => 'input')) ?> <?php echo $form['Profil|email']->renderRow(array('class' => 'input')) ?> <?php echo $form['Profil|phone']->renderRow(array('class' => 'input_short')) ?> <tr><td colspan="2"><h2>Dane firmy</h2></td></tr>
<?php echo $form['Profil|company_name']->renderRow(array('class' => 'input')) ?> <?php echo $form['Profil|company_nip']->renderRow(array('class' => 'input')) ?> <?php echo $form['Profil|company_regon']->renderRow(array('class' => 'input')) ?> <?php echo $form['Profil|company_address']->renderRow(array('class' => 'input')) ?> <?php echo $form['Profil|company_city']->renderRow(array('class' => 'input')) ?> <?php echo $form['Profil|company_postcode']->renderRow(array('class' => 'input_short')) ?> <tr><td colspan="2"><h2>Logo firmy</h2></td></tr>
<?php echo $form['Profil|company_logo']->renderRow(array('class' => 'input')) ?> <tr><td colspan="2"><h2>Logowanie</h2></td></tr>
<?php echo $form['username']->renderRow(array('class' => 'input_short')) ?> <?php echo $form['password']->renderRow(array('class' => 'input_short')) ?> <?php echo $form['password_confirmation']->renderRow(array('class' => 'input_short')) ?> <tr><td width="25%"> </td><td> </td></tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Rejestruj" />
</td>
</tr>
</table>
</form>