vendor/laravel/framework/src/Illuminate/Session/Store.php:142 - php

* #return string
*/
protected function prepareForUnserialize($data)
{
return $data;
}
/**
* Save the session data to storage.
*
* #return void
*/
public function save()
{
$this->ageFlashData();
$this->handler->write($this->getId(), $this->prepareForStorage(
serialize($this->attributes)
));
$this->started = false;
}
/**
* Prepare the serialized session data for storage.
*
* #param string $data
* #return string
*/
protected function prepareForStorage($data)

Related

Symfony2.3 Unrecognized field ORMexception

I'm having a similiar issue to Symfony2 Doctrine Unrecognized field:
But mine doesn't have the same solution
I have an entity "category" I'm trying to find all the categories with the attribute "activo" set to true but it gives me the error in the title
I've done php app/console doctrine:generate:entities [path] --no-backup and php app/console doctrine:schema:update --force
My table in my database is updated just as my entity.
<?php
namespace ROSHKA\BBVA\SitioExperience\FrontendBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Expcategorias
*/
class Expcategorias
{
/**
* #var integer
*/
private $id;
/**
* #var string
*/
private $nombre;
/**
* #var string
*/
private $descripcion;
/**
* #var \ROSHKA\BBVA\SitioUniversos\ImagenesBundle\Entity\Imagenes
*/
private $imagen;
/**
* #var string
*/
private $titulo;
/**
* #var boolean
*/
private $activo;
/**
* #var string
*/
private $colorfondo;
/**
* #var \ROSHKA\BBVA\SitioUniversos\ImagenesBundle\Entity\Imagenes
*/
private $imagenfondo;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set nombre
*
* #param string $nombre
* #return Expcategorias
*/
public function setNombre($nombre)
{
$this->nombre = $nombre;
return $this;
}
/**
* Get nombre
*
* #return string
*/
public function getNombre()
{
return $this->nombre;
}
/**
* Set descripcion
*
* #param string $descripcion
* #return Expcategorias
*/
public function setDescripcion($descripcion)
{
$this->descripcion = $descripcion;
return $this;
}
/**
* Get descripcion
*
* #return string
*/
public function getDescripcion()
{
return $this->descripcion;
}
/**
* Set imagen
*
* #param \ROSHKA\BBVA\SitioUniversos\ImagenesBundle\Entity\Imagenes $imagen
* #return Expcategorias
*/
public function setImagen(\ROSHKA\BBVA\SitioUniversos\ImagenesBundle\Entity\Imagenes $imagen = null)
{
$this->imagen = $imagen;
return $this;
}
/**
* Get imagen
*
* #return \ROSHKA\BBVA\SitioUniversos\ImagenesBundle\Entity\Imagenes
*/
public function getImagen()
{
return $this->imagen;
}
public function __toString()
{
return $this->getNombre();
}
/**
* Set titulo
*
* #param string $titulo
* #return Expcategorias
*/
public function setTitulo($titulo)
{
$this->titulo = $titulo;
return $this;
}
/**
* Get titulo
*
* #return string
*/
public function getTitulo()
{
return $this->titulo;
}
/**
* Set activo
*
* #param boolean $activo
* #return Expcategorias
*/
public function setActivo($activo)
{
$this->activo = $activo;
return $this;
}
/**
* Get activo
*
* #return boolean
*/
public function getActivo()
{
return $this->activo;
}
/**
* Set colorfondo
*
* #param string $colorfondo
* #return Expcategorias
*/
public function setColorfondo($colorfondo)
{
$this->colorfondo = $colorfondo;
return $this;
}
/**
* Get colorfondo
*
* #return string
*/
public function getColorfondo()
{
return $this->colorfondo;
}
/**
* Set imagenfondo
*
* #param \ROSHKA\BBVA\SitioUniversos\ImagenesBundle\Entity\Imagenes $imagenfondo
* #return Expcategorias
*/
public function setImagenfondo(\ROSHKA\BBVA\SitioUniversos\ImagenesBundle\Entity\Imagenes $imagenfondo = null)
{
$this->imagenfondo = $imagenfondo;
return $this;
}
/**
* Get imagenfondo
*
* #return \ROSHKA\BBVA\SitioUniversos\ImagenesBundle\Entity\Imagenes
*/
public function getImagenfondo()
{
return $this->imagenfondo;
}
}
This is what I use to call it in my controller. When I debug and set a breakpoint here i can see in the expressions sections that my category only has three columns instead of the 9 columns that should have. I don't know what else to do.
$repo = $this->getDoctrine()->getRepository('ROSHKABBVASitioExperienceFrontendBundle:Expcategorias');
$categorias = $repo->findBy(array('activo'=>true));
After thinking for a while I remembered I've installed memcached, then all I did was restart memcached in the task manager, then my project took all the new values.

Relation Many to Many Bidirectional Symfony 3

I'm using Symfony 3 with Doctrine. I have 2 entities in my application, User and Role. I need to make a bidirectional relationship many to many.
I consulted the doctrine documentation.Here is the code:
class Rol
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="nombre", type="string", length=255, unique=true)
*/
private $nombre;
/**
* #var string
*
* #ORM\Column(name="descripcion", type="string", length=255)
*/
private $descripcion;
/**
* #ORM\ManyToMany(targetEntity="Funcionalidad", inversedBy="rolesUsuario")
* #ORM\JoinTable(name="rol_funcionalidad")
*/
private $funcionalidades;
/**
* #ORM\ManyToMany(targetEntity="Usuario", mappedBy="rolesUsuario")
*/
private $usuarios;
public function getAttributes()
{
return get_class_vars(__CLASS__);
}
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set nombre
*
* #param string $nombre
*
* #return Rol
*/
public function setNombre($nombre)
{
$this->nombre = $nombre;
return $this;
}
/**
* Get nombre
*
* #return string
*/
public function getNombre()
{
return $this->nombre;
}
/**
* Set descripcion
*
* #param string $descripcion
*
* #return Rol
*/
public function setDescripcion($descripcion)
{
$this->descripcion = $descripcion;
return $this;
}
/**
* Get descripcion
*
* #return string
*/
public function getDescripcion()
{
return $this->descripcion;
}
/**
* #return string
*/
public function __toString()
{
return $this->getNombre();
}
/**
* Constructor
*/
public function __construct()
{
$this->funcionalidades = new \Doctrine\Common\Collections\ArrayCollection();
$this->usuarios = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add funcionalidade
*
* #param \CECMED\SeguridadBundle\Entity\Rol $funcionalidade
*
* #return Rol
*/
public function addFuncionalidade(\CECMED\SeguridadBundle\Entity\Rol $funcionalidade)
{
$this->funcionalidades[] = $funcionalidade;
return $this;
}
/**
* Remove funcionalidade
*
* #param \CECMED\SeguridadBundle\Entity\Rol $funcionalidade
*/
public function removeFuncionalidade(\CECMED\SeguridadBundle\Entity\Rol $funcionalidade)
{
$this->funcionalidades->removeElement($funcionalidade);
}
/**
* Get funcionalidades
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getFuncionalidades()
{
return $this->funcionalidades;
}
/**
* Add usuario
*
* #param \CECMED\SeguridadBundle\Entity\Usuario $usuario
*
* #return Rol
*/
public function addUsuario(\CECMED\SeguridadBundle\Entity\Usuario $usuario)
{
$usuario->addRolesUsuario($this);
$this->usuarios[] = $usuario;
return $this;
}
/**
* Remove usuario
*
* #param \CECMED\SeguridadBundle\Entity\Usuario $usuario
*/
public function removeUsuario(\CECMED\SeguridadBundle\Entity\Usuario $usuario)
{
$this->usuarios->removeElement($usuario);
}
/**
* Get usuarios
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getUsuarios()
{
return $this->usuarios;
}
}
This is the Usuario Class
class Usuario implements AdvancedUserInterface
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="username", type="string", length=255, unique=true)
*/
private $username;
/**
* #var string
*
* #ORM\Column(name="password", type="string", length=255)
*/
private $password;
/**
* #var string
*
* #ORM\Column(name="estado", type="boolean")
*/
private $estado;
/**
* #var string
*
* #ORM\Column(name="salt", type="string", length=255)
*/
private $salt;
/**
* #ORM\ManyToMany(targetEntity="Rol", inversedBy="usuarios")
* #ORM\JoinTable(name="usuario_rol")
*/
private $rolesUsuario;
/**
* #ORM\OneToOne(targetEntity="Persona")
* #ORM\JoinColumn(name="persona_id", referencedColumnName="id")
*/
private $persona;
public function getAttributes()
{
return get_class_vars(__CLASS__);
}
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set username
*
* #param string $username
*
* #return Usuario
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Get username
*
* #return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set password
*
* #param string $password
*
* #return Usuario
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* #return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set estado
*
* #param string $estado
*
* #return Usuario
*/
public function setEstado($estado)
{
$this->estado = $estado;
return $this;
}
/**
* Get estado
*
* #return string
*/
public function getEstado()
{
return $this->estado;
}
/**
* Checks whether the user's account has expired.
*
* Internally, if this method returns false, the authentication system
* will throw an AccountExpiredException and prevent login.
*
* #return bool true if the user's account is non expired, false otherwise
*
* #see AccountExpiredException
*/
public function isAccountNonExpired()
{
return true;
}
/**
* Checks whether the user is locked.
*
* Internally, if this method returns false, the authentication system
* will throw a LockedException and prevent login.
*
* #return bool true if the user is not locked, false otherwise
*
* #see LockedException
*/
public function isAccountNonLocked()
{
return true;
}
/**
* Checks whether the user's credentials (password) has expired.
*
* Internally, if this method returns false, the authentication system
* will throw a CredentialsExpiredException and prevent login.
*
* #return bool true if the user's credentials are non expired, false otherwise
*
* #see CredentialsExpiredException
*/
public function isCredentialsNonExpired()
{
return true;
}
/**
* Checks whether the user is enabled.
*
* Internally, if this method returns false, the authentication system
* will throw a DisabledException and prevent login.
*
* #return bool true if the user is enabled, false otherwise
*
* #see DisabledException
*/
public function isEnabled()
{
if($this->estado == true){
return true;
}else{
return false;
}
}
/**
* Returns the roles granted to the user.
*
* <code>
* public function getRoles()
* {
* return array('ROLE_USER');
* }
* </code>
*
* Alternatively, the roles might be stored on a ``roles`` property,
* and populated in any number of different ways when the user object
* is created.
*
* #return (Role|string)[] The user roles
*/
public function getRolesUsuario()
{
return $this->rolesUsuario;
}
public function getRoles()
{
$r = array();
foreach ($this->rolesUsuario as $roles){
$r[] = $roles->getNombre();
}
return $r;
}
/**
* Returns the salt that was originally used to encode the password.
*
* This can return null if the password was not encoded using a salt.
*
* #return string|null The salt
*/
public function getSalt()
{
return $this->salt;
}
/**
* Removes sensitive data from the user.
*
* This is important if, at any given point, sensitive information like
* the plain-text password is stored on this object.
*/
public function eraseCredentials()
{
return false;
}
/**
* Constructor
*/
public function __construct()
{
$this->rolesUsuario = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Set salt
*
* #param string $salt
*
* #return Usuario
*/
public function setSalt($salt)
{
$this->salt = $salt;
return $this;
}
/**
* Add role
*
* #param \CECMED\SeguridadBundle\Entity\Rol $role
*
* #return Usuario
*/
public function addRole(\CECMED\SeguridadBundle\Entity\Rol $role)
{
$this->rolesUsuario[] = $role;
return $this;
}
/**
* Remove role
*
* #param \CECMED\SeguridadBundle\Entity\Rol $role
*/
public function removeRole(\CECMED\SeguridadBundle\Entity\Rol $role)
{
$this->rolesUsuario->removeElement($role);
}
/**
* Set persona
*
* #param \CECMED\SeguridadBundle\Entity\persona $persona
*
* #return Usuario
*/
public function setPersona(\CECMED\SeguridadBundle\Entity\persona $persona = null)
{
$this->persona = $persona;
return $this;
}
/**
* Get persona
*
* #return \CECMED\SeguridadBundle\Entity\persona
*/
public function getPersona()
{
return $this->persona;
}
/**
* #return string
*/
public function __toString()
{
return $this->getUsername();
}
/**
* Add rolesUsuario
*
* #param \CECMED\SeguridadBundle\Entity\Rol $rolesUsuario
*
* #return Usuario
*/
public function addRolesUsuario(\CECMED\SeguridadBundle\Entity\Rol $rolesUsuario)
{
$this->rolesUsuario[] = $rolesUsuario;
return $this;
}
/**
* Remove rolesUsuario
*
* #param \CECMED\SeguridadBundle\Entity\Rol $rolesUsuario
*/
public function removeRolesUsuario(\CECMED\SeguridadBundle\Entity\Rol $rolesUsuario)
{
$this->rolesUsuario->removeElement($rolesUsuario);
}
}
The Problem is that, when i generate schema with cli and the CRUD,The Usuario form works fine and it registers the role in database, but the Rol form when I insert a record does not register the user in database
What I have found with my foreign keys in Symfony is #ORM\JoinColumn was redundant. Doctrine can find the column from the #ORM\ManyToMany on its own. It's not clear in the docs in my opinion. I have not tried this with Many to Many relationships, but I have done quite a few Many to Ones. I had several issues until I just deleted all the JoinColumns. Try it out. Let me know how it goes.

CollectionType field showing empty after manually submitting Symfony Form

I have OneToMany relationship
Book <----* BookImage
Book:
oneToMany:
bookImages:
targetEntity: BookImage
mappedBy: book
cascade: [persist,remove]
BookImage:
manyToOne:
book:
targetEntity: Book
inversedBy: bookImages
joinColumn:
name: book_id
referencedColumnName: id
So my Form has a collectionType field.
BookType:
$builder->add('bookImages', 'collection', array(
'type' => new BookImageType(),
'allow_add' => true,
// 'allow_delete' => true,
'by_reference' =>false
));
BookImageType:
$builder->add('imageName','text',array(
'constraints' => array(
new NotBlank(),
)
));
$builder->add('imageUrl','text',array(
'constraints' => array(
new NotBlank(),
)
));
Controller to save the data via Ajax Call:
public function addNewSellBookAction(Request $request)
{
$serializer = $this->container->get('jms_serializer');
$userId = $this->get('security.token_storage')->getToken()->getUser()->getId();
$em = $this->getDoctrine()->getManager();
$content = $request->get('book');
$bookData = json_decode($content, true);
$book = new Book();
$bookImage1 = new BookImage();
$bookImage1->setImageName("Amazon Book Image");
$bookImage1->setImageUrl("http://url1.com");
$book->addBookImage($bookImage1);
$bookImage2 = new BookImage();
$bookImage2->setImageName("Amazon Book Image");
$bookImage2->setImageUrl("http://url1.com");
$book->addBookImage($bookImage2);
$bookData['bookSeller']=$userId;
$bookForm = $this->createForm(new BookType(), $book);
var_dump($bookForm->getData()->getBookImages()); //Image Data Before Submit
$bookForm->submit($bookData);
var_dump($bookForm->getData()->getBookImages()); //Image Data After Submit
if($bookForm->isValid()){
$em->persist($book);
$em->flush();
return $this->createJsonResponse('success',array('successTitle'=>"Book Successfully added to sell List"));
}else{
$error= $serializer->serialize($bookForm,'json');
return new Response($error,200);
}
}
Now BookImage Data Before & After Submit are:
object(Doctrine\Common\Collections\ArrayCollection)[580]
private 'elements' =>
array (size=2)
0 =>
object(AppBundle\Entity\BookImage)[581]
protected 'id' => null
private 'imageName' => string 'Amazon Book Image' (length=17)
private 'imageUrl' => string 'http://url1.com' (length=15)
private 'titleImage' => null
private 'book' =>
object(AppBundle\Entity\Book)[578]
...
1 =>
object(AppBundle\Entity\BookImage)[582]
protected 'id' => null
private 'imageName' => string 'Amazon Book Image' (length=17)
private 'imageUrl' => string 'http://url1.com' (length=15)
private 'titleImage' => null
private 'book' =>
object(AppBundle\Entity\Book)[578]
...
object(Doctrine\Common\Collections\ArrayCollection)[580]
private 'elements' =>
array (size=2)
0 =>
object(AppBundle\Entity\BookImage)[581]
protected 'id' => null
private 'imageName' => null
private 'imageUrl' => null
private 'titleImage' => boolean false
private 'book' =>
object(AppBundle\Entity\Book)[578]
...
1 =>
object(AppBundle\Entity\BookImage)[582]
protected 'id' => null
private 'imageName' => null
private 'imageUrl' => null
private 'titleImage' => boolean false
private 'book' =>
object(AppBundle\Entity\Book)[578]
Why after submitting data the collectionType field value got null or empty? Though the other fields have the value perfectly. Can anyone explain? or do I have any problem with the structure? Thanks in advance.
Book Entity
class Book
{
/**
* Constructor
*/
public function __construct()
{
$this->messages = new ArrayCollection();
$this->bookImages = new ArrayCollection();
}
/**
* #var integer
*
*/
protected $id;
/**
* #var string
*
*/
private $bookTitle;
/**
* #var string
*
*/
private $bookDirectorAuthorArtist;
/**
* #var string
*
*/
private $bookEdition;
/**
* #var string
*
*/
private $bookIsbn10;
/**
* #var string
*
*/
private $bookIsbn13;
/**
* #var string
*
*/
private $bookPublisher;
/**
* #var date
*
*/
private $bookPublishDate;
/**
* #var string
*
*/
private $bookBinding;
/**
* #var string
*
*/
private $bookPage;
/**
* #var string
*
*/
private $bookPriceSell;
/**
* #var string
*
*/
private $bookLanguage;
/**
* #var text
*
*/
private $bookDescription;
/**
* #var string
*
*/
private $bookCondition;
/**
* #var string
*
*/
private $bookIsHighlighted;
/**
* #var string
*
*/
private $bookHasNotes;
/**
* #var string
*
*/
private $bookComment;
/**
* #var string
*
*/
private $bookContactMethod;
/**
* #var string
*
*/
private $bookContactHomeNumber;
/**
* #var string
*
*/
private $bookContactCellNumber;
/**
* #var string
*
*/
private $bookContactEmail;
/**
* #var string
*
*/
private $bookIsAvailablePublic;
/**
* #var boolean
*
*/
private $bookPaymentMethodCaShOnExchange;
/**
* #var boolean
*
*/
private $bookPaymentMethodCheque;
/**
* #var date
*
*/
private $bookAvailableDate;
private $bookImages;
private $bookBuyer;
private $bookSeller;
private $messages;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set bookTitle
*
* #param string $bookTitle
* #return Book
*/
public function setBookTitle($bookTitle)
{
$this->bookTitle = $bookTitle;
return $this;
}
/**
* Get bookTitle
*
* #return string
*/
public function getBookTitle()
{
return $this->bookTitle;
}
/**
* Set bookDirectorAuthorArtist
*
* #param string $bookDirectorAuthorArtist
* #return Book
*/
public function setBookDirectorAuthorArtist($bookDirectorAuthorArtist)
{
$this->bookDirectorAuthorArtist = $bookDirectorAuthorArtist;
return $this;
}
/**
* Get bookDirectorAuthorArtist
*
* #return string
*/
public function getBookDirectorAuthorArtist()
{
return $this->bookDirectorAuthorArtist;
}
/**
* Set bookEdition
*
* #param string $bookEdition
* #return Book
*/
public function setBookEdition($bookEdition)
{
$this->bookEdition = $bookEdition;
return $this;
}
/**
* Get bookEdition
*
* #return string
*/
public function getBookEdition()
{
return $this->bookEdition;
}
/**
* Set bookIsbn10
*
* #param string $bookIsbn10
* #return Book
*/
public function setBookIsbn10($bookIsbn10)
{
$this->bookIsbn10 = $bookIsbn10;
return $this;
}
/**
* Get bookIsbn10
*
* #return string
*/
public function getBookIsbn10()
{
return $this->bookIsbn10;
}
/**
* Set bookIsbn13
*
* #param string $bookIsbn13
* #return Book
*/
public function setBookIsbn13($bookIsbn13)
{
$this->bookIsbn13 = $bookIsbn13;
return $this;
}
/**
* Get bookIsbn13
*
* #return string
*/
public function getBookIsbn13()
{
return $this->bookIsbn13;
}
/**
* Set bookPublisher
*
* #param string $bookPublisher
* #return Book
*/
public function setBookPublisher($bookPublisher)
{
$this->bookPublisher = $bookPublisher;
return $this;
}
/**
* Get bookPublisher
*
* #return string
*/
public function getBookPublisher()
{
return $this->bookPublisher;
}
/**
* Set bookPublishDate
*
* #param \DateTime $bookPublishDate
* #return Book
*/
public function setBookPublishDate($bookPublishDate)
{
$this->bookPublishDate = $bookPublishDate;
return $this;
}
/**
* Get bookPublishDate
*
* #return \DateTime
*/
public function getBookPublishDate()
{
return $this->bookPublishDate;
}
/**
* Set bookBinding
*
* #param string $bookBinding
* #return Book
*/
public function setBookBinding($bookBinding)
{
$this->bookBinding = $bookBinding;
return $this;
}
/**
* Get bookBinding
*
* #return string
*/
public function getBookBinding()
{
return $this->bookBinding;
}
/**
* Set bookPage
*
* #param string $bookPage
* #return Book
*/
public function setBookPage($bookPage)
{
$this->bookPage = $bookPage;
return $this;
}
/**
* Get bookPage
*
* #return string
*/
public function getBookPage()
{
return $this->bookPage;
}
/**
* Set bookLanguage
*
* #param string $bookLanguage
* #return Book
*/
public function setBookLanguage($bookLanguage)
{
$this->bookLanguage = $bookLanguage;
return $this;
}
/**
* Get bookLanguage
*
* #return string
*/
public function getBookLanguage()
{
return $this->bookLanguage;
}
/**
* Add messages
*
* #param \AppBundle\Entity\Message $messages
* #return Book
*/
public function addMessage(\AppBundle\Entity\Message $messages)
{
$this->messages[] = $messages;
return $this;
}
/**
* Remove messages
*
* #param \AppBundle\Entity\Message $messages
*/
public function removeMessage(\AppBundle\Entity\Message $messages)
{
$this->messages->removeElement($messages);
}
/**
* Get messages
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getMessages()
{
return $this->messages;
}
/**
* Set bookBuyer
*
* #param \AppBundle\Entity\User $bookBuyer
* #return Book
*/
public function setBookBuyer(\AppBundle\Entity\User $bookBuyer = null)
{
$this->bookBuyer = $bookBuyer;
return $this;
}
/**
* Get bookBuyer
*
* #return \AppBundle\Entity\User
*/
public function getBookBuyer()
{
return $this->bookBuyer;
}
/**
* Set bookSeller
*
* #param \AppBundle\Entity\User $bookSeller
* #return Book
*/
public function setBookSeller(\AppBundle\Entity\User $bookSeller = null)
{
$this->bookSeller = $bookSeller;
return $this;
}
/**
* Get bookSeller
*
* #return \AppBundle\Entity\User
*/
public function getBookSeller()
{
return $this->bookSeller;
}
/**
* Set bookPriceSell
*
* #param string $bookPriceSell
* #return Book
*/
public function setBookPriceSell($bookPriceSell)
{
$this->bookPriceSell = $bookPriceSell;
return $this;
}
/**
* Get bookPriceSell
*
* #return string
*/
public function getBookPriceSell()
{
return $this->bookPriceSell;
}
/**
* Set bookDescription
*
* #param string $bookDescription
* #return Book
*/
public function setBookDescription($bookDescription)
{
$this->bookDescription = $bookDescription;
return $this;
}
/**
* Get bookDescription
*
* #return string
*/
public function getBookDescription()
{
return $this->bookDescription;
}
/**
* Set bookCondition
*
* #param string $bookCondition
* #return Book
*/
public function setBookCondition($bookCondition)
{
$this->bookCondition = $bookCondition;
return $this;
}
/**
* Get bookCondition
*
* #return string
*/
public function getBookCondition()
{
return $this->bookCondition;
}
/**
* Set bookIsHighlighted
*
* #param string $bookIsHighlighted
* #return Book
*/
public function setBookIsHighlighted($bookIsHighlighted)
{
$this->bookIsHighlighted = $bookIsHighlighted;
return $this;
}
/**
* Get bookIsHighlighted
*
* #return string
*/
public function getBookIsHighlighted()
{
return $this->bookIsHighlighted;
}
/**
* Set bookHasNotes
*
* #param string $bookHasNotes
* #return Book
*/
public function setBookHasNotes($bookHasNotes)
{
$this->bookHasNotes = $bookHasNotes;
return $this;
}
/**
* Get bookHasNotes
*
* #return string
*/
public function getBookHasNotes()
{
return $this->bookHasNotes;
}
/**
* Set bookComment
*
* #param string $bookComment
* #return Book
*/
public function setBookComment($bookComment)
{
$this->bookComment = $bookComment;
return $this;
}
/**
* Get bookComment
*
* #return string
*/
public function getBookComment()
{
return $this->bookComment;
}
/**
* Set bookContactMethod
*
* #param string $bookContactMethod
* #return Book
*/
public function setBookContactMethod($bookContactMethod)
{
$this->bookContactMethod = $bookContactMethod;
return $this;
}
/**
* Get bookContactMethod
*
* #return string
*/
public function getBookContactMethod()
{
return $this->bookContactMethod;
}
/**
* Set bookContactHomeNumber
*
* #param string $bookContactHomeNumber
* #return Book
*/
public function setBookContactHomeNumber($bookContactHomeNumber)
{
$this->bookContactHomeNumber = $bookContactHomeNumber;
return $this;
}
/**
* Get bookContactHomeNumber
*
* #return string
*/
public function getBookContactHomeNumber()
{
return $this->bookContactHomeNumber;
}
/**
* Set bookContactCellNumber
*
* #param string $bookContactCellNumber
* #return Book
*/
public function setBookContactCellNumber($bookContactCellNumber)
{
$this->bookContactCellNumber = $bookContactCellNumber;
return $this;
}
/**
* Get bookContactCellNumber
*
* #return string
*/
public function getBookContactCellNumber()
{
return $this->bookContactCellNumber;
}
/**
* Set bookContactEmail
*
* #param string $bookContactEmail
* #return Book
*/
public function setBookContactEmail($bookContactEmail)
{
$this->bookContactEmail = $bookContactEmail;
return $this;
}
/**
* Get bookContactEmail
*
* #return string
*/
public function getBookContactEmail()
{
return $this->bookContactEmail;
}
/**
* Set bookIsAvailablePublic
*
* #param string $bookIsAvailablePublic
* #return Book
*/
public function setBookIsAvailablePublic($bookIsAvailablePublic)
{
$this->bookIsAvailablePublic = $bookIsAvailablePublic;
return $this;
}
/**
* Get bookIsAvailablePublic
*
* #return string
*/
public function getBookIsAvailablePublic()
{
return $this->bookIsAvailablePublic;
}
/**
* Set bookPaymentMethodCaShOnExchange
*
* #param string $bookPaymentMethodCaShOnExchange
* #return Book
*/
public function setBookPaymentMethodCaShOnExchange($bookPaymentMethodCaShOnExchange)
{
$this->bookPaymentMethodCaShOnExchange = $bookPaymentMethodCaShOnExchange;
return $this;
}
/**
* Get bookPaymentMethodCaShOnExchange
*
* #return string
*/
public function getBookPaymentMethodCaShOnExchange()
{
return $this->bookPaymentMethodCaShOnExchange;
}
/**
* Set bookPaymentMethodCheck
*
* #param string $bookPaymentMethodCheck
* #return Book
*/
public function setBookPaymentMethodCheck($bookPaymentMethodCheck)
{
$this->bookPaymentMethodCheck = $bookPaymentMethodCheck;
return $this;
}
/**
* Get bookPaymentMethodCheck
*
* #return string
*/
public function getBookPaymentMethodCheck()
{
return $this->bookPaymentMethodCheck;
}
/**
* Add bookImages
*
* #param \AppBundle\Entity\BookImage $bookImages
* #return Book
*/
public function addBookImage(\AppBundle\Entity\BookImage $bookImages)
{
$this->bookImages->add($bookImages);
$bookImages->setBook($this);
return $this;
}
/**
* Remove bookImages
*
* #param \AppBundle\Entity\BookImage $bookImages
*/
public function removeBookImage(\AppBundle\Entity\BookImage $bookImages)
{
$this->bookImages->removeElement($bookImages);
}
/**
* Get bookImages
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getBookImages()
{
return $this->bookImages;
}
/**
* Set bookPaymentMethodCheque
*
* #param boolean $bookPaymentMethodCheque
* #return Book
*/
public function setBookPaymentMethodCheque($bookPaymentMethodCheque)
{
$this->bookPaymentMethodCheque = $bookPaymentMethodCheque;
return $this;
}
/**
* Get bookPaymentMethodCheque
*
* #return boolean
*/
public function getBookPaymentMethodCheque()
{
return $this->bookPaymentMethodCheque;
}
/**
* Set bookAvailableDate
*
* #param \DateTime $bookAvailableDate
* #return Book
*/
public function setBookAvailableDate($bookAvailableDate)
{
$this->bookAvailableDate = $bookAvailableDate;
return $this;
}
/**
* Get bookAvailableDate
*
* #return \DateTime
*/
public function getBookAvailableDate()
{
return $this->bookAvailableDate;
}
public function __toString()
{
return strval($this->id);
}
}
BookImage Entity
class BookImage
{
/**
* #var integer
*
*/
protected $id;
/**
* #var string
*
*/
private $imageName;
/**
* #var string
*
*/
private $imageUrl;
/**
* #var boolean
*
*/
private $titleImage;
private $book;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set imageName
*
* #param string $imageName
* #return BookImage
*/
public function setImageName($imageName)
{
$this->imageName = $imageName;
return $this;
}
/**
* Get imageName
*
* #return string
*/
public function getImageName()
{
return $this->imageName;
}
/**
* Set imageUrl
*
* #param string $imageUrl
* #return BookImage
*/
public function setImageUrl($imageUrl)
{
$this->imageUrl = $imageUrl;
return $this;
}
/**
* Get imageUrl
*
* #return string
*/
public function getImageUrl()
{
return $this->imageUrl;
}
/**
* Set titleImage
*
* #param boolean $titleImage
* #return BookImage
*/
public function setTitleImage($titleImage)
{
$this->titleImage = $titleImage;
return $this;
}
/**
* Get titleImage
*
* #return boolean
*/
public function getTitleImage()
{
return $this->titleImage;
}
/**
* Set book
*
* #param \AppBundle\Entity\Book $book
* #return BookImage
*/
public function setBook(\AppBundle\Entity\Book $book = null)
{
$this->book = $book;
return $this;
}
/**
* Get book
*
* #return \AppBundle\Entity\Book
*/
public function getBook()
{
return $this->book;
}
public function __toString()
{
return strval($this->id);
}
}
I have been trying to find the answer for almost 7 days now and finally came up with a solution. But don't know if it a bad practice or not.
Just have to put the data as an array into submitData. After submitting the value will be added to that particular entity via form.
public function addNewSellBookAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$serializer = $this->container->get('jms_serializer');
$userId = $this->get('security.token_storage')->getToken()->getUser()->getId();
$content = $request->get('book');
$bookData = json_decode($content, true);
$bookData['bookImages']=array();
array_push($bookData['bookImages'],array(
'imageName'=>"Amazon Book Image",
'imageUrl'=>"http://url1.com"
));
array_push($bookData['bookImages'],array(
'imageName'=>"Amazon Book Image",
'imageUrl'=>"http://url1.com"
));
$bookData['bookSeller']=$userId;
$book = new Book();
$bookForm = $this->createForm(new BookType(),$book);
var_dump($bookForm->getData()->getBookImages());
$bookForm->submit($bookData);
var_dump($book->getBookImages());
if($bookForm->isValid()){
$em->persist($book);
$em->flush();
return $this->createJsonResponse('success',array('successTitle'=>"Book Successfully added to sell List"));
}else{
$error= $serializer->serialize($bookForm,'json');
return new Response($error,200);
}
}
Hope it will help the others.
Bounty Still Open If anyone provides answer with best practice
I'm not sure. As per the documentation by symfony
Check Task controller line number 20 and 23
$task->getTags()->add($tag2);
The tags collection is accessible naturally via $task->getTags() and can be persisted to the database or used however you need.
I think you are missing something here
$book->addBookImage($bookImage1);
Try this instead
$book->getBookImages()->add($bookImage1);
If you don't need to modify images with the request data add new images after you submit the form.
$bookForm->submit($bookData);
// ...
$book->addBookImage($bookImage1);

Retrieve user from existing table User

I'm really new to Symfony and I'm learning how it works.
So I have a DB and a table on it called USER with the fields name,username,password etc etc.
I'm trying to create a login form that will take the user from that table.
I've already created my enity User
I've read the doc here, but it's not what I want, because as i said my entity it's still there.
Should I use FOS user bunble? I've read the doc here of this bundle, but I didn't get the final part (step7).So my question is, can I use my User Entity with FOS user Bundle? If the answer is no, there is another solution to that, sicne I don't what to change my DB table?
Thank everyone in advance
P.s I generated the User entity following this dochere and this is the resulting class
namespace LocalWorker\BackendBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Utente
*/
class Utente
{
/**
* #var string
*/
private $uNome;
/**
* #var string
*/
private $uCognome;
/**
* #var string
*/
private $uUsername;
/**
* #var string
*/
private $uPassword;
/**
* #var string
*/
private $uEmail;
/**
* #var string
*/
private $uRuolo;
/**
* #var integer
*/
private $uStatus;
/**
* #var \DateTime
*/
private $uDateIns;
/**
* #var \DateTime
*/
private $uDateActive;
/**
* #var integer
*/
private $uId;
/**
* Set uNome
*
* #param string $uNome
* #return Utente
*/
public function setUNome($uNome)
{
$this->uNome = $uNome;
return $this;
}
/**
* Get uNome
*
* #return string
*/
public function getUNome()
{
return $this->uNome;
}
/**
* Set uCognome
*
* #param string $uCognome
* #return Utente
*/
public function setUCognome($uCognome)
{
$this->uCognome = $uCognome;
return $this;
}
/**
* Get uCognome
*
* #return string
*/
public function getUCognome()
{
return $this->uCognome;
}
/**
* Set uUsername
*
* #param string $uUsername
* #return Utente
*/
public function setUUsername($uUsername)
{
$this->uUsername = $uUsername;
return $this;
}
/**
* Get uUsername
*
* #return string
*/
public function getUUsername()
{
return $this->uUsername;
}
/**
* Set uPassword
*
* #param string $uPassword
* #return Utente
*/
public function setUPassword($uPassword)
{
$this->uPassword = $uPassword;
return $this;
}
/**
* Get uPassword
*
* #return string
*/
public function getUPassword()
{
return $this->uPassword;
}
/**
* Set uEmail
*
* #param string $uEmail
* #return Utente
*/
public function setUEmail($uEmail)
{
$this->uEmail = $uEmail;
return $this;
}
/**
* Get uEmail
*
* #return string
*/
public function getUEmail()
{
return $this->uEmail;
}
/**
* Set uRuolo
*
* #param string $uRuolo
* #return Utente
*/
public function setURuolo($uRuolo)
{
$this->uRuolo = $uRuolo;
return $this;
}
/**
* Get uRuolo
*
* #return string
*/
public function getURuolo()
{
return $this->uRuolo;
}
/**
* Set uStatus
*
* #param integer $uStatus
* #return Utente
*/
public function setUStatus($uStatus)
{
$this->uStatus = $uStatus;
return $this;
}
/**
* Get uStatus
*
* #return integer
*/
public function getUStatus()
{
return $this->uStatus;
}
/**
* Set uDateIns
*
* #param \DateTime $uDateIns
* #return Utente
*/
public function setUDateIns($uDateIns)
{
$this->uDateIns = $uDateIns;
return $this;
}
/**
* Get uDateIns
*
* #return \DateTime
*/
public function getUDateIns()
{
return $this->uDateIns;
}
/**
* Set uDateActive
*
* #param \DateTime $uDateActive
* #return Utente
*/
public function setUDateActive($uDateActive)
{
$this->uDateActive = $uDateActive;
return $this;
}
/**
* Get uDateActive
*
* #return \DateTime
*/
public function getUDateActive()
{
return $this->uDateActive;
}
/**
* Get uId
*
* #return integer
*/
public function getUId()
{
return $this->uId;
}
}

->find($id) in entity returns an empty proxy object symfony2

I'm doing a search on an entity, but this returns me a proxy object. Thus I am trying to do the search.
$em = $this->getDoctrine()->getEntityManager();
$tipou = $em->getRepository('SertecomvendoautosBundle:TipoUsuario')->find(5);
In the database, table tipo_usuario I have only two records with ID 4 and 5, but to make the search with ID 4, doctrine returns the object for me and not the proxy object that returns me with ID 5.
$em = $this->getDoctrine()->getEntityManager();
$tipou = $em->getRepository('SertecomvendoautosBundle:TipoUsuario')->find(4);
This brings the object in the normal way.
Really do not understand this behavior that doctrine, I would like to know what happens with this.
This is code of entity tipo_usuario.
class TipoUsuario {
/**
* #var string $tipouNombre
*/
private $tipouNombre;
/**
* #var string $tipouToken
*/
private $tipouToken;
/**
* #var datetime $tipouCreatedAt
*/
private $tipouCreatedAt;
/**
* #var datetime $tipouUpdatedAt
*/
private $tipouUpdatedAt;
/**
* #var integer $tipouId
*/
private $tipouId;
/**
* Set tipouNombre
*
* #param string $tipouNombre
*/
public function setTipouNombre($tipouNombre)
{
$this->tipouNombre = $tipouNombre;
}
/**
* Get tipouNombre
*
* #return string
*/
public function getTipouNombre()
{
return $this->tipouNombre;
}
/**
* Set tipouToken
*
* #param string $tipouToken
*/
public function setTipouToken($tipouToken)
{
$this->tipouToken = $tipouToken;
}
/**
* Get tipouToken
*
* #return string
*/
public function getTipouToken()
{
return $this->tipouToken;
}
/**
* Set tipouCreatedAt
*
* #param datetime $tipouCreatedAt
*/
public function setTipouCreatedAt($tipouCreatedAt)
{
$this->tipouCreatedAt = $tipouCreatedAt;
}
/**
* Get tipouCreatedAt
*
* #return datetime
*/
public function getTipouCreatedAt()
{
return $this->tipouCreatedAt;
}
/**
* Set tipouUpdatedAt
*
* #param datetime $tipouUpdatedAt
*/
public function setTipouUpdatedAt($tipouUpdatedAt)
{
$this->tipouUpdatedAt = $tipouUpdatedAt;
}
/**
* Get tipouUpdatedAt
*
* #return datetime
*/
public function getTipouUpdatedAt()
{
return $this->tipouUpdatedAt;
}
/**
* Get tipouId
*
* #return integer
*/
public function getTipouId()
{
return $this->tipouId;
}

Categories