It seems like it isn't possible to create a form because frameworkbundle is not found. I really don't know how to fix the problem.
I tried to use different methods for creating form and i am using the following link to make this work http://symfony.com/doc/current/cookbook/doctrine/registration_form.html
<?php
namespace Forms;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class UserType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('username', 'username');
$builder->add('email', 'email');
$builder->add('password', 'repeated', array(
'first_name' => 'password',
'second_name' => 'confirm',
'type' => 'password',
));
}
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setDefaults(array(
'data_class' => '\Entities\User'
));
}
public function getName()
{
return 'user';
}
}
This is the form that builds the form and then i have the controller to show the form on the webpage.
<?php
namespace Controllers;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Forms\UserType;
class RegisterController extends Controller
{
public function get(Request $request)
{
$registration = new UserType();
$form = $this->createForm(new UserType(), $registration, array(
'action' => $this->generateUrl('account_create'),
));
if($form->isValid())
{
$data = $form->getData();
echo $data;
return $app->redirect('login');
}
return $app['twig']->render('register.twig', array('form' => $form->createView()));
}
}
Do not actually know if it may fix your problem, but there is an error in your code:
$registration = new UserType();
$form = $this->createForm(new UserType(), $registration, array(
'action' => $this->generateUrl('account_create'),
));
You should pass the new User
object as the second parameter to $this->createForm
method, but not the form object. See method docs here .
You should create your user object & then pass it to createForm()
:
$user = new User();
$form = $this->createForm(new UserType(), $user, array(
'action' => $this->generateUrl('account_create'),
));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.