Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class contacts
- {
- /**
- * @var int
- */
- private $id;
- /**
- * @var string
- * @AssertNotBlank()
- * )
- * @AssertRegex(
- * pattern="/d/",
- * match=false,
- * message="Your first name cannot contain a number"
- * )
- */
- private $firstName;
- /**
- * @var string
- * @AssertNotBlank()
- * @Asserttype(
- * type="string"
- * )
- * @AssertRegex(
- * pattern="/d/",
- * match=false,
- * message="Your last name cannot contain a number"
- * )
- */
- private $lastName;
- /**
- * @var string
- * @AssertRegex(
- * pattern="/d/",
- * match=true,
- * message="Your phone number cannot contain a character"
- * )
- * @AssertRegex(
- * pattern="/d{11}/",
- * match=true,
- * message="Your phone number should have 11 digits no more no less :)"
- * )
- */
- private $phoneNumber;
- /**
- * @var string
- * @AssertEmail(
- * message = "The email '{{ value }}' is not a valid email.",
- * checkMX = true
- * )
- */
- private $emailAddress;
- /**
- * @var integer
- */
- private $User;
- /**
- * @return mixed
- */
- public function getUser()
- {
- return $this->User;
- }
- /**
- * @param mixed $user
- */
- public function setUser($user)
- {
- $this->User = $user;
- }
- /**
- * Get id
- *
- * @return int
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set firstName
- *
- * @param string $firstName
- *
- * @return contacts
- */
- public function setFirstName($firstName)
- {
- $this->firstName = $firstName;
- return $this;
- }
- /**
- * Get firstName
- *
- * @return string
- */
- public function getFirstName()
- {
- return $this->firstName;
- }
- /**
- * Set lastName
- *
- * @param string $lastName
- *
- * @return contacts
- */
- public function setLastName($lastName)
- {
- $this->lastName = $lastName;
- return $this;
- }
- /**
- * Get lastName
- *
- * @return string
- */
- public function getLastName()
- {
- return $this->lastName;
- }
- /**
- * Set phoneNumber
- *
- * @param string $phoneNumber
- *
- * @return contacts
- */
- public function setPhoneNumber($phoneNumber)
- {
- $this->phoneNumber = $phoneNumber;
- return $this;
- }
- /**
- * Get phoneNumber
- *
- * @return string
- */
- public function getPhoneNumber()
- {
- return $this->phoneNumber;
- }
- /**
- * Set emailAddress
- *
- * @param string $emailAddress
- *
- * @return string
- */
- public function setEmailAddress($emailAddress)
- {
- $this->emailAddress = $emailAddress;
- return $this;
- }
- /**
- * Get emailAddress
- *
- * @return string
- */
- public function getEmailAddress()
- {
- return $this->emailAddress;
- }
- }
- /**
- * User
- */
- class User implements UserInterface , Serializable
- {
- /**
- * @var int
- */
- private $id;
- /**
- * @var string
- * * @AssertNotBlank()
- * * )
- * * @AssertRegex(
- * pattern="/d/",
- * match=false,
- * message="Your first name cannot contain a number"
- * )
- */
- private $firstName;
- /**
- * @var string
- * * @AssertNotBlank()
- * @Asserttype(
- * type="string"
- * )
- * * @AssertRegex(
- * pattern="/d/",
- * match=false,
- * message="Your last name cannot contain a number"
- * )
- */
- private $lastName;
- /**
- * @var string
- * * @var string
- * * @AssertEmail(
- * message = "The email '{{ value }}' is not a valid email.",
- * checkMX = true
- * )
- */
- public $email;
- /**
- * @var string
- */
- private $password;
- /**
- * @var string
- */
- private $Role;
- /**
- * Get id
- *
- * @return integer
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set firstName
- *
- * @param string $firstName
- *
- * @return User
- */
- public function setFirstName($firstName)
- {
- $this->firstName = $firstName;
- return $this;
- }
- /**
- * Get firstName
- *
- * @return string
- */
- public function getFirstName()
- {
- return $this->firstName;
- }
- /**
- * Set lastName
- *
- * @param string $lastName
- *
- * @return User
- */
- public function setLastName($lastName)
- {
- $this->lastName = $lastName;
- return $this;
- }
- /**
- * Get lastName
- *
- * @return string
- */
- public function getLastName()
- {
- return $this->lastName;
- }
- /**
- * Set email
- *
- * @param string $email
- *
- * @return User
- */
- public function setEmail($email)
- {
- $this->email = $email;
- return $this;
- }
- /**
- * Get email
- *
- * @return string
- */
- public function getEmail()
- {
- return $this->email;
- }
- /**
- * Set password
- *
- * @param string $password
- *
- * @return User
- */
- public function setPassword($password)
- {
- $this->password = $password;
- return $this;
- }
- /**
- * Get password
- *
- * @return string
- */
- public function getPassword()
- {
- return $this->password;
- }
- public function setRole($Role = null)
- {
- $this->Role = $Role;
- return $this;
- }
- /**
- * Get Role
- *
- * @return string
- */
- public function getRole()
- {
- return $this->Role;
- }
- public function getRoles()
- {
- return [ $this->getRole()];
- }
- public function getSalt()
- {
- return null;
- }
- public function getUsername()
- {
- return $this->email;
- }
- public function eraseCredentials()
- {
- return null;
- }
- public function serialize()
- {
- return serialize(array(
- $this->id,
- $this->email,
- $this->password,
- ));
- }
- public function unserialize($serialized)
- {
- list (
- $this->id,
- $this->email,
- $this->password,
- ) = unserialize($serialized);
- }
- }
- manyToOne:
- User:
- targetEntity: UserBundleEntityUser
- inversedBy: contacts
- joinColumn:
- name: user_Id
- nullable: true
- referencedColumnName: id
- uniqueConstraints:
- idx:
- columns: phone_number,user_Id
- public function addAction(Request $request)
- {
- $contact = new contacts();
- $userses = $this->get("security.token_storage")->getToken()
- ->getUser()->getid();
- $form = $this->createForm(addForm::class, $contact);
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid()) {
- $data = $form->getData();
- $data->setUser($userses);
- $em = $this->getDoctrine()->getManager();
- $em->persist($data);
- $em->flush();
- return $this->render('/add/index.html.twig', array(
- 'form' => $form->createView(),
- ));
- } else return $this->render('/add/index.html.twig', array(
- 'form' => $form->createView(),
- ));
- }
Add Comment
Please, Sign In to add comment