0

送信ボタンを押したときに実行される次のコードがあります (POST 要求アクション)。

public function earlySignupAction(Request $request)
{
    $user = new User();

    $form = $this->createFormBuilder($user)
        ->add('username', 'text')
        ->add('email', 'text')
        ->add('password', 'password')
        ->getForm();

    $form->bind($request);

    if ($form->isValid()) {
        $em = $this->getDoctrine()->getEntityManager();
        $userRepository = $em->getRepository('SiteUserBundle:User');
        $userFoundByUsername = $userRepository->findOneBy(array('username' => $user->getUsername()));

        if ($userFoundByUsername) {
            $this->get('session')->getFlashBag()->add('notice', "Already registered!\n We will notify you soon!");
        } else {
            $session = $this->getRequest()->getSession();
            $session->set('user', $user);
        }

        return $this->redirect($this->generateUrl('SiteMainBundle_signup_additional_info'));
    }else{
        foreach($form->getErrors() as $key => $error){
            $this->get('session')->getFlashBag()->add('error', $error->getMessage());
        }    
    }

    return $this->redirect($this->generateUrl('ShopiousMainBundle_signup_fail'));
}

小枝の中に私は次のものを持っています:

<form id="registerMiniForm" class="clearfix"  action="{{ path('SiteMainBundle_early_signup') }}" method="post" {{ form_enctype(userForm) }} novalidate>
                        {{ form_widget(userForm.username, { 'attr': {'class': 'validate[required,minSize[3]] arvo-regular', 'placeholder': 'Username'} }) }}
                        {{ form_widget(userForm.password, { 'attr': {'class': 'validate[required] arvo-regular', 'placeholder': 'Password'} }) }}
                        {{ form_widget(userForm.email, { 'attr': {'class': 'validate[required,custom[email],ajax[ajaxEmailCall]] input', 'placeholder': 'Email'} }) }}
                        {{ form_rest(userForm) }}
                        <div class="register-wrap">
                            <input class="arvo-bold button" type="submit" value="Register" />
                        </div>
                    </form>

$user 変数を印刷しようとしたときに、メールが表示されません。なぜですか?

class Site\UserBundle\Entity\User#367 (47) { protected $id => NULL protected $firstname => NULL protected $lastname => NULL protected $dni => NULL protected $birthday => NULL protected $website => NULL protected $biography => NULL protected $address => NULL protected $city => NULL protected $state => NULL protected $zipcode => NULL protected $phone => NULL protected $isFirstTimeAuthUsingFB => bool(true) protected $facebookId => NULL protected $profilePicture => NULL protected $shop => NULL protected $notification => NULL protected $shippingInfo => NULL protected $shoppingCart => NULL protected $paymentInfo => NULL private $followers => NULL private $following => NULL protected $invitedFriends => NULL protected $itemlikes => NULL protected $likeCount => int(0) protected $itemComments => NULL protected $commentCount => int(0) protected $shopTestimonials => NULL private $fullName => NULL protected $username => string(11) "alksdjasdla" protected $usernameCanonical => string(11) "alksdjasdla" protected $email => NULL protected $emailCanonical => NULL protected $enabled => bool(false) protected $salt => string(31) "jjkgwyjbnv488ccskk80wkc8gk4w080" protected $password => string(14) "lkasjdaslkdasd" protected $plainPassword => NULL protected $lastLogin => NULL protected $confirmationToken => NULL protected $passwordRequestedAt => NULL protected $groups => NULL protected $locked => bool(false) protected $expired => bool(false) protected $expiresAt => NULL protected $roles => NULL protected $credentialsExpired => bool(false) protected $credentialsExpireAt => NULL }
4

1 に答える 1

0

$user は永続化されず、プロパティをバインドした後にデータベースにフラッシュされます

persist()flush()呼び出しを追加して、この行を閉じます

 $session = $this->getRequest()->getSession();
 $session->set('user', $user) ;

 $em->persist($user);
 $em->flush();
于 2013-03-29T09:06:34.710 に答える