Mam zainstalowaną wtyczkę sfDoctrineGuard. Domyślnie w tabeli sf_guard_user kolumna is_active ma wartość = 1, a ja chciałbym żeby domyslnie było 0. Jak zmieniałem w tabeli na domyslnie '0' i zbudowałem schemat itd. to jak robię teraz rejestrację to i tak po rejestracji nowy użytkownik ma is_active=1. Wiem, że można zrobić zapytanie zmieniające is_active po dodaniu użytkownika na 0, ale w symfony na pewno jest krótszy sposób ?
Jak w formularzu rejestracyjnym ustawiałem to pole na domyślnie 0 to i tak po dodaniu użytkownika było 1:
<?php
class RejestracjaForm extends sfGuardUserForm
{
public function configure()
{
$this['id'],
$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']
);
//$this->widgetSchema['is_active'] = new sfWidgetFormInput();
$this->widgetSchema['password'] = new sfWidgetFormInputPassword();
$this->widgetSchema['password_confirmation'] = new sfWidgetFormInputPassword();
$this->widgetSchema['imie'] = new sfWidgetFormInput();
$this->widgetSchema['nazwisko'] = new sfWidgetFormInput();
$this->widgetSchema['email'] = new sfWidgetFormInput();
//$this->setDefaults(array('is_active' => 0));
$this->widgetSchema->setLabels(array( 'username' => 'Login',
'password' => 'Hasło',
'password_confirmation' => 'Powtórz hasło',
));
$this->setValidators(array( 'username' => new sfValidatorString
(array('max_length' => 50, 'min_length' => 5, 'required' => true), array('required' => 'Nie wpisano loginu.', 'max_length' => 'Zbyt długi login.', 'min_length' => 'Zbyt krótki login.')),
'password' => new sfValidatorString
(array('max_length' => 50, 'min_length' => 5, 'required' => true), array('required' => 'Nie wpisano hasła.', 'max_length' => 'Zbyt długe hasło.', 'min_length' => 'Zbyt krótkie hasło.')),
'password_confirmation' => new sfValidatorString
(array('max_length' => 50, 'min_length' => 5, 'required' => true), array('required' => 'Nie wpisano hasła.', 'max_length' => 'Zbyt długe hasło.', 'min_length' => 'Zbyt krótkie hasło.')),
'email' => new sfValidatorEmail
(array(), array('invalid' => 'Wprowadzono bledny email.')),
'imie' => new sfValidatorString
(array('min_length' => 2, 'max_length' => 50
), array('required' => 'Imie jest wymagane.', 'min_length' => 'Imie jest za krótkie.', 'max_length' => 'Imie jest za długie.')),
'nazwisko' => new sfValidatorString
(array('min_length' => 2, 'max_length' => 100
), array('required' => 'Nazwisko jest wymagane.', 'min_length' => 'Nazwisko jest za krótkie.', 'max_length' => 'Nazwisko jest za długie.')),
));
$this->mergePostValidator(new sfValidatorSchemaCompare
('password', sfValidatorSchemaCompare
::EQUAL, 'password_confirmation', array(), array('invalid' => 'Hasła muszą być takie same.')));
}
}
?>
Jak po dodaniu uzytkownika probowalem ustawic za pomoca setIsActive na 0 to też nic z tego:
<?php
class rejestracjaActions extends sfActions
{
public function executeIndex(sfWebRequest $request)
{
$this->form = new RejestracjaForm();
if ($request->isMethod('post'))
{
$this->form->bind($request->getParameter('sf_guard_user'));
if ($this->form->isValid())
{
$conn = Doctrine_Manager::connection();
//rozpoczecie transakcji bo dodaje do dwoch tabel - uzytkownika do sf_guard_user, a jego profil do sf_guard_user_profile:
$conn->beginTransaction();
try
{
$uzytkownik = $this->form->save();
//$uzytkownik->setIsActive(0);
$profil = new SfGuardUserProfile();
$profil -> setUserId($uzytkownik->getId());
$profil -> setImie($this->form->getValue('imie'));
$profil -> setNazwisko($this->form->getValue('nazwisko'));
$profil -> setEmail($this->form->getValue('email'));
$profil -> save();
$conn->commit();
}
catch (Exception $e)
{
$conn->rollBack();
throw $e;
}
}
}
}
}
?>
Ten post edytował nieraczek 8.03.2009, 13:48:19