2016-12-12 10:05
浏览 40

twig / symfony中既没有属性“password”也没有其中一种方法

I want to make reuse of the form field by passing show_password_field as true in the optional value in AddUserType.php. My edit form field should not contain password field. So I have used this

if ($options['show_password_field']) {

in form type. Can anybody figure it out? What is the problem in line 37 of twig file.

Neither the property "password" nor one of the methods "password()", "getpassword()"/"ispassword()" or "__call()" exist and have public access in class "Symfony\Component\Form\FormView" in SokosimuEditorBundle:User:addUser.html.twig at line 37.


   namespace Sokosimu\EditorBundle\Form\Type;

   use Symfony\Component\Form\AbstractType;
   use Symfony\Component\Form\FormBuilderInterface;
   use Symfony\Component\Form\Extension\Core\Type\SubmitType;
   use Symfony\Component\OptionsResolver\OptionsResolverInterface;

  class AddUserType extends AbstractType

 public function buildForm(FormBuilderInterface $builder, array $options)
    $builder->add('email', 'email',array('required'=>false));

    if ($options['show_password_field']) {

    $builder->add('submit', 'submit');

public function setDefaultOptions(OptionsResolverInterface $resolver)
        'data_class' => 'Sokosimu\UserBundle\Entity\User',
        'show_password_field' => true

 * Returns the name of this type.
 * @return string The name of this type
 public function getName()
     return 'adduser';

And line 37 in addUser.html.twig

<div class="form-group">
   <label for="password">Password:</label>
   {{ form_widget(form.password,{'attr':{'class':'form-row'}}) }}
   {{ form_errors(form.password) }}

Controller that renders edit

public function editEditorUserAction(User $user,Request $request){

    $form = $this->createForm(new AddUserType(),$user,array(
        'show_password_field' => false));

    if($form ->isValid() && $form->isSubmitted()){
        $em = $this->get('doctrine')->getManager();
        $editUser = $user ->getEditoruser();


        return $this->redirect($this->generateUrl('sokosimu_editor_userlist'));

    return $this->render('SokosimuEditorBundle:User:addUser.html.twig', array(
        'form' => $form->createView(),
         'user' => $user->getId()
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题