-1

I have created an update password form and whenever I try to submit the data I got error like The class 'RetailMapping\Bundle\UserBundle\Form\Model\ChangePassword' was not found in the chain configured namespaces AppBundle\Entity, RetailMapping\Bundle\UserBundle\Entity, RetailMapping\Bundle\CatalogBundle\Entity, RetailMapping\Bundle\LocationBundle\Entity, RetailMapping\Bundle\ClassificationBundle\Entity, RetailMapping\Bundle\RetailOutletBundle\Entity, FOS\UserBundle\Model. What am I doing wrong in here? The error occurs when I try to save the data in the database. Here are my codes. This is my ChangePasswordType.php

<?php

namespace RetailMapping\Bundle\UserBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class ChangePasswordType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array                $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('oldPassword', 'password');
        $builder->add('newPassword', 'repeated', array(
            'type' => 'password',
            'invalid_message' => 'The password fields must match.',
            'required' => true,
            'first_options'  => array('label' => 'Password'),
            'second_options' => array('label' => 'Repeat Password'),
        ));
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
                'data_class' => 'RetailMapping\Bundle\UserBundle\Form\Model\ChangePassword',
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'retailmapping_bundle_userbundle_password_chnage';
    }
}

This is my ChangePassword.php

<?php
namespace RetailMapping\Bundle\UserBundle\Form\Model;

use Symfony\Component\Security\Core\Validator\Constraints as SecurityAssert;
use Symfony\Component\Validator\Constraints as Assert;

class ChangePassword
{
     /**
      * @SecurityAssert\UserPassword(
      *     message = "Wrong value for your current password"
      * )
      */
     protected $oldPassword;

     /**
      * @Assert\Length(
      *     min = 6,
      *     minMessage = "Password should by at least 6 chars long"
      * )
      */
     protected $newPassword;

    public function setOldPassword($oldPassword)
    {
        $this->oldPassword = $oldPassword;
    }

    public function getOldPassword()
    {
        return $this->oldPassword;
    }

    public function setNewPassword($newPassword)
    {
        $this->newPassword = $newPassword;
    }

    public function getNewPassword()
    {
        return $this->newPassword;
    }
}

This is my UserController.php

<?php
namespace RetailMapping\Bundle\UserBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use RetailMapping\Bundle\UserBundle\Form\ChangePasswordType;
use Symfony\Component\HttpFoundation\Request;
use RetailMapping\Bundle\UserBundle\Form\Model\ChangePassword;

class UserController extends Controller
{
public function editPasswordAction(Request $request)
    {
        $form = $this->createForm(new ChangePasswordType(), new ChangePassword());
        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            $data = $form->getData();
            $form->getData();
            $em = $this->getDoctrine()->getManager();
            $em->persist($data);
            $em->flush();
            dump($form->getData());
            die;
        }

        return $this->render('User/editPassword.html.twig', [
                'form' => $form->createView(),
        ]);
    }
}
4
  • add id field in ChangePassword entity Commented Mar 10, 2015 at 8:33
  • @StrawHat why would I need an Id field? I already have that in the user entity. Commented Mar 10, 2015 at 8:49
  • because every entity has to have a primary key Commented Mar 10, 2015 at 8:54
  • 1
    you are doing it wrong. ChangePassword should not be an entity, you are not going to store it in database Commented Mar 10, 2015 at 8:55

2 Answers 2

1

There's no mention of an Entity in the post you linked. Because you made the class an Entity, it's become a database table, and fields like id's are expected.

Double check the answer you tried to implement.

Sign up to request clarification or add additional context in comments.

4 Comments

Double checked and corrected. Now I am getting this err. Neither the property "oldPassword" nor one of the methods "getOldPassword()", "oldPassword()", "isOldPassword()", "hasOldPassword()", "__get()" exist and have public access in class "RetailMapping\Bundle\UserBundle\Form\Model\ChangePassword"
Try changing 'protected $oldPassword;' to 'public $oldPassword;'
Please add the error/stacktrace with the linenumbers etc you get..class 'XXX' is unclear.
0

For making a password update form you need to make PasswordUpdateModel and PasswordUpdateType, after processing form you can assign it to UserEntity fields.

I hope this helps.

3 Comments

Yes , I get the idea and I have followed the answer from the above link I provided in the question. But now when I tried to submit the form I got this err The class XXX was not found in the chain configured namespaces
Did you set 'data_class' option for your form type?
I got this error. The class 'RetailMapping\Bundle\UserBundle\Form\Model\ChangePassword' was not found in the chain configured namespaces AppBundle\Entity, RetailMapping\Bundle\UserBundle\Entity, RetailMapping\Bundle\CatalogBundle\Entity, RetailMapping\Bundle\LocationBundle\Entity, RetailMapping\Bundle\ClassificationBundle\Entity, RetailMapping\Bundle\RetailOutletBundle\Entity, FOS\UserBundle\Model

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.