Related
I have 2 entities - Product and category.
But i have in symfony dev toolbar the error - Invalid Entities 2.
The exact error is:
Entities Mapping
Class Mapping errors
AppBundle\Entity\category
The association AppBundle\Entity\category#products refers to the owning side field AppBundle\Entity\Product#category which does not exist.
AppBundle\Entity\Product
The association AppBundle\Entity\Product#categoryId refers to the inverse side field AppBundle\Entity\category#product which does not exist.here
I've tried many times fix the relastion following symfony docs, but it dosn't works.
So, please, tell were am i wrong....
Here are my 2 entities:
Product
<?php
namespace AppBundle\Entity;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
/**
* Product
*
* #ORM\Table(name="products")
* #ORM\Entity(repositoryClass="AppBundle\Repository\ProductRepository")
*/
class Product
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="sku", type="string", length=255, unique=true)
*/
private $sku;
/**
*
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\category", inversedBy="product")
* #ORM\JoinColumn(name="categoryId", referencedColumnName="id")
*/
private $categoryId;
/**
* #var string
*
* #ORM\Column(name="image", type="string", length=255, nullable=true)
* #Assert\File(
* maxSize="5242880",
* mimeTypes = {
* "image/png",
* "image/jpeg",
* "image/jpg",
* "image/gif",
* }
* )
*/
private $image;
/**
* #var string
*
* #ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* #var string
*
* #ORM\Column(name="price", type="decimal", precision=10, scale=2, nullable=true)
*/
private $price;
/**
* #var bool
*
* #ORM\Column(name="isActive", type="boolean", nullable=true)
*/
private $isActive;
/**
* #var int
*
* #ORM\Column(name="quantity", type="integer", nullable=true)
*/
private $quantity;
/**
* #var decimal
*/
private $percent;
/**
* #var decimal
*/
private $endPrice;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* #param string $name
*
* #return Product
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set sku
*
* #param string $sku
*
* #return Product
*/
public function setSku($sku)
{
$this->sku = $sku;
return $this;
}
/**
* Get sku
*
* #return string
*/
public function getSku()
{
return $this->sku;
}
/**
* Set categoryId
*
* #param integer $categoryId
*
* #return Product
*/
public function setCategoryId($categoryId)
{
$this->categoryId = $categoryId;
return $this;
}
/**
* Get categoryId
*
* #return int
*/
public function getCategoryId()
{
return $this->categoryId;
}
/**
* Set image
*
* #param string $image
*
* #return Product
*/
public function setImage($image)
{
$this->image = $image;
return $this;
}
/**
* Get image
*
* #return string
*/
public function getImage()
{
return $this->image;
}
/**
* Set description
*
* #param string $description
*
* #return Product
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set price
*
* #param string $price
*
* #return Product
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* Get price
*
* #return string
*/
public function getPrice()
{
return $this->price;
}
/**
* Set isActive
*
* #param boolean $isActive
*
* #return Product
*/
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
/**
* Get isActive
*
* #return bool
*/
public function getIsActive()
{
return $this->isActive;
}
/**
* Set quantity
*
* #param integer $quantity
*
* #return Product
*/
public function setQuantity($quantity)
{
$this->quantity = $quantity;
return $this;
}
/**
* Get quantity
*
* #return int
*/
public function getQuantity()
{
return $this->quantity;
}
/**
* #return decimal
*/
public function getPercent()
{
return $this->percent;
}
/**
* #param decimal $percent
*/
public function setPercent($percent)
{
if(null != $percent) {
$this->percent = $percent;
}
}
/**
* #return decimal
*/
public function getEndPrice()
{
return $this->endPrice;
}
/**
* #param decimal $endPrice
*/
public function setEndPrice($endPrice)
{
$this->endPrice = $endPrice;
}
}
.........................................................................................................................................................................................................................................
category
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* category
*
* #ORM\Table(name="category")
* #ORM\Entity(repositoryClass="AppBundle\Repository\categoryRepository")
*/
class category
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* #var int
*
* #ORM\Column(name="parent", type="integer", nullable=true)
*/
private $parent;
/**
* #var bool
*
* #ORM\Column(name="isActive", type="boolean", nullable=true)
*/
private $isActive;
/**
* #ORM\OneToMany(targetEntity="AppBundle\Entity\Product" , mappedBy="category")
*/
private $products;
public function __construct()
{
$this->products = new ArrayCollection();
}
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* #param string $name
*
* #return category
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set parent
*
* #param integer $parent
*
* #return category
*/
public function setParent($parent)
{
$this->parent = $parent;
return $this;
}
/**
* Get parent
*
* #return int
*/
public function getParent()
{
return $this->parent;
}
/**
* Set isActive
*
* #param boolean $isActive
*
* #return category
*/
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
/**
* Get isActive
*
* #return bool
*/
public function getIsActive()
{
return $this->isActive;
}
public function __toString()
{
return $this->id."";
}
/**
* #return mixed
*/
public function getProducts()
{
return $this->products;
}
/**
* #param mixed $products
*/
public function setProducts($products)
{
$this->products = $products;
}
}
How to fix it?
Try replacing in Product entity this
private $categoryId;
By this
private $category;
Don't forget to change the getter & setter
try to change this:
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\category", inversedBy="product")
to this:
* #ORM\ManyToOne(targetEntity="Category", inversedBy="products")
and this:
* #ORM\OneToMany(targetEntity="AppBundle\Entity\Product" , mappedBy="category")
to this:
* #ORM\OneToMany(targetEntity="Product" , mappedBy="category")
Trying to solve this problem with Join in Symfony3.
Somehow the resultset has mixed up values, i.e
ID Exploit Author
ID Author Author
Please see the attached screenshot.
OpenX should have Author Metasploit and the second row shouldn't be there.
Have this code in the controller:
public function indexAction()
{
$exploits = $this->getDoctrine()
->getRepository('AppBundle:Exploit')->createQueryBuilder('e')
->add('select', 'a,e')
->add('from', 'AppBundle:Exploit e')
->leftJoin('AppBundle:Author', 'a')
->where('e.author = a.id')
->getQuery()
->getResult();
return $this->render('exploit/index.html.twig', array(
'exploits' => $exploits
));
}
This view:
<tbody>
{% for exploit in exploits %}
<tr>
<th scope="row">{{ exploit.id }}</th>
<td>{{ exploit.name }}</td>
<td> {{ exploit.author }} </td>
<td>
View
Edit
Delete
</td>
</tr>
{% endfor %}
And these Entities:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Author
*
* #ORM\Table(name="author", indexes={#ORM\Index(name="author_name_id_idx", columns={"id"})})
* #ORM\Entity
*/
class Author
{
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* #var \Exploit
*
* #ORM\Id
* #ORM\GeneratedValue(strategy="NONE")
* #ORM\OneToOne(targetEntity="Exploit")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="id", referencedColumnName="author")
* })
*/
private $id;
/**
* Set name
*
* #param string $name
*
* #return Author
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
public function getAuthor()
{
return $this->name;
}
}
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Author
*
* #ORM\Table(name="author", indexes={#ORM\Index(name="author_name_id_idx", columns={"id"})})
* #ORM\Entity
*/
class Author
{
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* #var \Exploit
*
* #ORM\Id
* #ORM\GeneratedValue(strategy="NONE")
* #ORM\OneToOne(targetEntity="Exploit")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="id", referencedColumnName="author")
* })
*/
private $id;
}
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Category
*
* #ORM\Table(name="category", indexes={#ORM\Index(name="category_name_id_idx", columns={"id"})})
* #ORM\Entity
*/
class Category
{
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* #var \Exploit
*
* #ORM\Id
* #ORM\GeneratedValue(strategy="NONE")
* #ORM\OneToOne(targetEntity="Exploit")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="id", referencedColumnName="category")
* })
*/
private $id;
/**
* Set name
*
* #param string $name
*
* #return Category
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
}
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Category
*
* #ORM\Table(name="category", indexes={#ORM\Index(name="category_name_id_idx", columns={"id"})})
* #ORM\Entity
*/
class Category
{
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* #var \Exploit
*
* #ORM\Id
* #ORM\GeneratedValue(strategy="NONE")
* #ORM\OneToOne(targetEntity="Exploit")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="id", referencedColumnName="category")
* })
*/
private $id;
}
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Exploit
*
* #ORM\Table(name="exploit", indexes={#ORM\Index(name="exploit_category_idx", columns={"category"}), #ORM\Index(name="exploit_type_idx", columns={"type"}), #ORM\Index(name="exploit_author_idx", columns={"author"})})
* #ORM\Entity
*/
class Exploit
{
/**
* #var integer
*
* #ORM\Column(name="id", type="bigint", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="edb_id", type="string", length=100, nullable=false)
*/
private $edbId;
/**
* #var \DateTime
*
* #ORM\Column(name="date", type="datetime", nullable=false)
*/
private $date;
/**
* #var integer
*
* #ORM\Column(name="author", type="bigint", nullable=false)
*/
private $author;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* #var integer
*
* #ORM\Column(name="category", type="bigint", nullable=false)
*/
private $category;
/**
* #var string
*
* #ORM\Column(name="version", type="string", length=255, nullable=false)
*/
private $version;
/**
* #var integer
*
* #ORM\Column(name="type", type="bigint", nullable=false)
*/
private $type;
/**
* #var string
*
* #ORM\Column(name="content", type="text", nullable=false)
*/
private $content;
/**
* #var string
*
* #ORM\Column(name="dork", type="string", length=255, nullable=true)
*/
private $dork;
/**
* #var string
*
* #ORM\Column(name="software_link", type="string", length=255, nullable=true)
*/
private $softwareLink;
/**
* #var string
*
* #ORM\Column(name="tested_on", type="string", length=255, nullable=true)
*/
private $testedOn;
/**
* Set edbId
*
* #param integer $edbId
*
* #return Exploit
*/
public function setEdbId($edbId)
{
$this->edbId = $edbId;
return $this;
}
/**
* Get edbId
*
* #return integer
*/
public function getEdbId()
{
return $this->edbId;
}
/**
* Set date
*
* #param \DateTime $date
*
* #return Exploit
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* Get date
*
* #return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* Set author
*
* #param integer $author
*
* #return Exploit
*/
public function setAuthor($author)
{
$this->author = $author;
return $this;
}
/**
* Get author
*
* #return integer
*/
public function getAuthor()
{
return $this->author;
}
/**
* Set name
*
* #param string $name
*
* #return Exploit
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set category
*
* #param integer $category
*
* #return Exploit
*/
public function setCategory($category)
{
$this->category = $category;
return $this;
}
/**
* Get category
*
* #return integer
*/
public function getCategory()
{
return $this->category;
}
/**
* Set version
*
* #param string $version
*
* #return Exploit
*/
public function setVersion($version)
{
$this->version = $version;
return $this;
}
/**
* Get version
*
* #return string
*/
public function getVersion()
{
return $this->version;
}
/**
* Set type
*
* #param integer $type
*
* #return Exploit
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Get type
*
* #return integer
*/
public function getType()
{
return $this->type;
}
/**
* Set content
*
* #param string $content
*
* #return Exploit
*/
public function setContent($content)
{
$this->content = $content;
return $this;
}
/**
* Get content
*
* #return string
*/
public function getContent()
{
return $this->content;
}
/**
* Set dork
*
* #param string $dork
*
* #return Exploit
*/
public function setDork($dork)
{
$this->dork = $dork;
return $this;
}
/**
* Get dork
*
* #return string
*/
public function getDork()
{
return $this->dork;
}
/**
* Set softwareLink
*
* #param string $softwareLink
*
* #return Exploit
*/
public function setSoftwareLink($softwareLink)
{
$this->softwareLink = $softwareLink;
return $this;
}
/**
* Get softwareLink
*
* #return string
*/
public function getSoftwareLink()
{
return $this->softwareLink;
}
/**
* Set testedOn
*
* #param string $testedOn
*
* #return Exploit
*/
public function setTestedOn($testedOn)
{
$this->testedOn = $testedOn;
return $this;
}
/**
* Get testedOn
*
* #return string
*/
public function getTestedOn()
{
return $this->testedOn;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
}
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Exploit
*
* #ORM\Table(name="exploit", indexes={#ORM\Index(name="exploit_category_idx", columns={"category"}), #ORM\Index(name="exploit_type_idx", columns={"type"}), #ORM\Index(name="exploit_author_idx", columns={"author"})})
* #ORM\Entity
*/
class Exploit
{
/**
* #var integer
*
* #ORM\Column(name="id", type="bigint", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="edb_id", type="string", length=100, nullable=false)
*/
private $edbId;
/**
* #var \DateTime
*
* #ORM\Column(name="date", type="datetime", nullable=false)
*/
private $date;
/**
* #var integer
*
* #ORM\Column(name="author", type="bigint", nullable=false)
*/
private $author;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* #var integer
*
* #ORM\Column(name="category", type="bigint", nullable=false)
*/
private $category;
/**
* #var string
*
* #ORM\Column(name="version", type="string", length=255, nullable=false)
*/
private $version;
/**
* #var integer
*
* #ORM\Column(name="type", type="bigint", nullable=false)
*/
private $type;
/**
* #var string
*
* #ORM\Column(name="content", type="text", nullable=false)
*/
private $content;
/**
* #var string
*
* #ORM\Column(name="dork", type="string", length=255, nullable=true)
*/
private $dork;
/**
* #var string
*
* #ORM\Column(name="software_link", type="string", length=255, nullable=true)
*/
private $softwareLink;
/**
* #var string
*
* #ORM\Column(name="tested_on", type="string", length=255, nullable=true)
*/
private $testedOn;
}
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Type
*
* #ORM\Table(name="type", indexes={#ORM\Index(name="type_name_id_idx", columns={"id"})})
* #ORM\Entity
*/
class Type
{
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* #var \Exploit
*
* #ORM\Id
* #ORM\GeneratedValue(strategy="NONE")
* #ORM\OneToOne(targetEntity="Exploit")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="id", referencedColumnName="type")
* })
*/
private $id;
/**
* Set name
*
* #param string $name
*
* #return Type
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
}
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Type
*
* #ORM\Table(name="type", indexes={#ORM\Index(name="type_name_id_idx", columns={"id"})})
* #ORM\Entity
*/
class Type
{
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* #var \Exploit
*
* #ORM\Id
* #ORM\GeneratedValue(strategy="NONE")
* #ORM\OneToOne(targetEntity="Exploit")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="id", referencedColumnName="type")
* })
*/
private $id;
}
Anybody know how to correct my join query ? Or why it behaves like this?
Thanks,
Try this:
->leftJoin('AppBundle:Author', 'a', "WITH", "e.author = a.id")
Instead of this:
->leftJoin('AppBundle:Author', 'a')
->where('e.author = a.id')
Try
public function indexAction()
{
$exploits = $this->getDoctrine()
->getRepository('AppBundle:Exploit')->createQueryBuilder('e')
->leftjoin('e.author','a')
->addSelect('a')
->getQuery()
->getResult();
return $this->render('exploit/index.html.twig', array(
'exploits' => $exploits
));
}
and in the view
<tbody>
{% for exploit in exploits %}
<tr>
<th scope="row">{{ exploit.id }}</th>
<td>{{ exploit.name }}</td>
<td> {{ exploit.author.name }} </td>
<td>
View
Edit
Delete
</td>
</tr>
{% endfor %}
</tbody>
I generated the CRUD for the entity Evenement(event) , which is working. But now I want to update a field in another entity called notification everytime an Evenement is added. Each Evenement has a categorie
Evenement.php:
<?php
namespace Mql14\mqlmeBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Mql14\mqlmeBundle\Entity\Evenement
*
* #ORM\Table(name="evenement")
* #ORM\Entity
*/
class Evenement
{
/**
* #var integer $id
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string $nom
*
* #ORM\Column(name="nom", type="string", length=45, nullable=true)
*/
private $nom;
/**
* #var datetime $date
*
* #ORM\Column(name="date", type="datetime", nullable=true)
*/
private $date;
/**
* #var string $description
*
* #ORM\Column(name="description", type="string", length=400, nullable=true)
*/
private $description;
/**
* #var integer $ticket
*
* #ORM\Column(name="Ticket", type="integer", nullable=true)
*/
private $ticket;
/**
* #var User
*
* #ORM\ManyToMany(targetEntity="User", mappedBy="evenement")
*/
private $user;
/**
* #var Categorie
*
* #ORM\ManyToOne(targetEntity="Categorie", inversedBy="evenement")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="categorie_id", referencedColumnName="id")
* })
*/
private $categorie;
/**
* #var Lieu
*
* #ORM\ManyToOne(targetEntity="Lieu")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="lieu_id", referencedColumnName="id")
* })
*/
private $lieu;
public function __construct()
{
$this->user = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set nom
*
* #param string $nom
*/
public function setNom($nom)
{
$this->nom = $nom;
}
/**
* Get nom
*
* #return string
*/
public function getNom()
{
return $this->nom;
}
/**
* Set date
*
* #param datetime $date
*/
public function setDate($date)
{
$this->date = $date;
}
/**
* Get date
*
* #return datetime
*/
public function getDate()
{
return $this->date;
}
/**
* Set description
*
* #param string $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* Get description
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set ticket
*
* #param integer $ticket
*/
public function setTicket($ticket)
{
$this->ticket = $ticket;
}
/**
* Get ticket
*
* #return integer
*/
public function getTicket()
{
return $this->ticket;
}
/**
* Add user
*
* #param Mql14\mqlmeBundle\Entity\User $user
*/
public function addUser(\Mql14\mqlmeBundle\Entity\User $user)
{
$this->user[] = $user;
}
/**
* Get user
*
* #return Doctrine\Common\Collections\Collection
*/
public function getUser()
{
return $this->user;
}
/**
* Set categorie
*
* #param Mql14\mqlmeBundle\Entity\Categorie $categorie
*/
public function setCategorie(\Mql14\mqlmeBundle\Entity\Categorie $categorie)
{
$this->categorie = $categorie;
}
/**
* Get categorie
*
* #return Mql14\mqlmeBundle\Entity\Categorie
*/
public function getCategorie()
{
return $this->categorie;
}
/**
* Set lieu
*
* #param Mql14\mqlmeBundle\Entity\Lieu $lieu
*/
public function setLieu(\Mql14\mqlmeBundle\Entity\Lieu $lieu)
{
$this->lieu = $lieu;
}
/**
* Get lieu
*
* #return Mql14\mqlmeBundle\Entity\Lieu
*/
public function getLieu()
{
return $this->lieu;
}
public function getCategorieId(\Mql14\mqlmeBundle\Entity\Categorie $categorie)
{
$idc= $categorie->getId();
return $idc;
}
}
Categorie.php:
<?php
namespace Mql14\mqlmeBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Mql14\mqlmeBundle\Entity\Categorie
*
* #ORM\Table(name="categorie")
* #ORM\Entity
*/
class Categorie
{
/**
* #var integer $id
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string $nomcat
*
* #ORM\Column(name="nomCat", type="string", length=45, nullable=true)
*/
private $nomcat;
/**
* #var string $photo
*
* #ORM\Column(name="photo", type="string", length=45, nullable=true)
*/
private $photo;
/**
* #var $evenement
*
* #ORM\OneToMany(targetEntity="Evenement", mappedBy="categorie")
*/
private $evenement;
/**
* #var User
*
* #ORM\ManyToMany(targetEntity="User", mappedBy="categorie")
*/
private $user;
public function __construct()
{
$this->user = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set nomcat
*
* #param string $nomcat
*/
public function setNomcat($nomcat)
{
$this->nomcat = $nomcat;
}
/**
* Get nomcat
*
* #return string
*/
public function getNomcat()
{
return $this->nomcat;
}
/**
* Set photo
*
* #param string $photo
*/
public function setPhoto($photo)
{
$this->photo = $photo;
}
/**
* Get photo
*
* #return string
*/
public function getPhoto()
{
return $this->photo;
}
/**
* Add user
*
* #param Mql14\mqlmeBundle\Entity\User $user
*/
public function addUser(\Mql14\mqlmeBundle\Entity\User $user)
{
$this->user[] = $user;
}
/**
* Get user
*
* #return Doctrine\Common\Collections\Collection
*/
public function getUser()
{
return $this->user;
}
/**
* Add evenement
*
* #param Mql14\mqlmeBundle\Entity\Categorie $evenement
*/
public function addEvenement(\Mql14\mqlmeBundle\Entity\Evenement $evenement)
{
$this->evenement[] = $evenement;
}
/**
* Get evenement
*
* #return Doctrine\Common\Collections\Collection
*/
public function getEvenement()
{
return $this->evenement;
}
}
Notification.php:
<?php
namespace Mql14\mqlmeBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Mql14\mqlmeBundle\Entity\Notification
*
* #ORM\Table(name="notification")
* #ORM\Entity
*/
class Notification
{
/**
* #var integer $id
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string $etat
*
* #ORM\Column(name="etat", type="integer", nullable=true)
*/
private $etat;
/**
* #var User
*
* #ORM\ManyToOne(targetEntity="User")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="User_id", referencedColumnName="id")
*
* })
*/
private $user;
/**
* #var Categorie
*
* #ORM\ManyToOne(targetEntity="Categorie")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="Categorie_id", referencedColumnName="id")
*
* })
*/
private $categorie;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set etat
*
* #param string $etat
*/
public function setEtat($etat)
{
$this->etat = $etat;
}
/**
* Get etat
*
* #return string
*/
public function getEtat()
{
return $this->etat;
}
/**
* Set user
*
* #param Mql14\mqlmeBundle\Entity\User $user
*/
public function setUser(\Mql14\mqlmeBundle\Entity\User $user)
{
$this->user = $user;
}
/**
* Get user
*
* #return Mql14\mqlmeBundle\Entity\User
*/
public function getUser()
{
return $this->user;
}
/**
* Set categorie
*
* #param Mql14\mqlmeBundle\Entity\Categorie $categorie
*/
public function setCategorie(\Mql14\mqlmeBundle\Entity\Categorie $categorie)
{
$this->categorie = $categorie;
}
/**
* Get categorie
*
* #return Mql14\mqlmeBundle\Entity\Categorie
*/
public function getCategorie()
{
return $this->categorie;
}
}
In the createAction that was generated after the execution of the CRUD for the Evenement entity I added the update query :
public function createAction(Request $request)
{
$entity = new Evenement();
$request = $this->getRequest();
$form = $this->createForm(new EvenementType(), $entity);
$form->bindRequest($request);
$entity->upload();
$cat=$entity->getCategorie();
if ($cat) {
$catn = $cat->getNomCat();
$query = $this->container->get('doctrine')->getEntityManager()->createQuery( 'UPDATE Mql14mqlmeBundle:Notification n SET n.etat=1 WHERE n.categorie LIKE :catn ' );
$query->setParameter('categorie', $catn);
$query->execute();
}
if ($form->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('mql14mqlme_adminshow', array('id' => $entity->getId())));
}
return array(
'entity' => $entity,
'form' => $form->createView(),
);
}
And the error I'm getting is this:
[Semantical Error] line 0, col 61 near 'categorie LIKE': Error:
Invalid PathExpression. Must be a StateFieldPathExpression.
You set the wrong parameter in the update query.
On this line:
$query = $this->container->get('doctrine')->getEntityManager()->createQuery(
'UPDATE Mql14mqlmeBundle:Notification n SET n.etat=1
WHERE n.categorie LIKE :catn' );
$query->setParameter('categorie', $catn);
$query->execute();
It should be:
$query = $this->container->get('doctrine')->getEntityManager()->createQuery(
'UPDATE Mql14mqlmeBundle:Notification n SET n.etat=1
WHERE n.categorie LIKE :catn' );
$query->setParameter('catn', $catn);
$query->execute();
n.categorie is an entity (of type Mql14\mqlmeBundle\Entity\Categorie) and you can't compare entities using LIKE.
Try replacing LIKE with =.
Change
UPDATE Mql14mqlmeBundle:Notification n SET n.etat=1 WHERE n.categorie LIKE :catn
To
UPDATE Mql14mqlmeBundle:Notification n SET n.etat=1 WHERE n.categorie = :catn
I'm trying to solve my problem but after many hours of search, It doesn't work :(
So I've got a class :
<?php
namespace Application\HappyBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Bar
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="Application\HappyBundle\Entity\BarRepository")
*/
class Bar
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
* #Assert\NotBlank()
* #ORM\Column(name="name", type="string", length=45)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="address", type="string", length=255)
*/
private $address;
/**
* #var string
*
* #ORM\Column(name="addressComplete", type="string", length=255)
*/
private $addressComplete;
/**
* #var string
*
* #ORM\Column(name="postal_code", type="string", length=5, nullable=true)
*/
private $postalCode;
/**
* #var string
*
* #ORM\Column(name="town", type="string", length=45)
*/
private $town;
/**
* #var string
*
* #ORM\Column(name="country", type="string", length=45)
*/
private $country;
/**
* #var string
*
* #ORM\Column(name="latitude", type="string", length=20)
*/
private $latitude;
/**
* #var string
*
* #ORM\Column(name="longitude", type="string", length=20)
*/
private $longitude;
/**
* #var array
*
* #ORM\Column(name="validate", type="boolean", nullable=false)
*/
private $validate;
/**
* #var \DateTime
*
* #ORM\Column(name="last_update", type="datetime", nullable=true)
*/
private $lastUpdate;
/**
* #var ArrayCollection of AssocBarDay
* #Assert\Valid
* #ORM\OneToMany(targetEntity="Application\HappyBundle\Entity\AssocBarDay", mappedBy="bar" , cascade={"persist" , "remove"})
*/
private $day;
/**
* #ORM\OneToMany(targetEntity="Application\HappyBundle\Entity\AssocBarDrink", mappedBy="drink", cascade={"persist"})
*/
private $drink;
/**
* #ORM\OneToMany(targetEntity="Application\HappyBundle\Entity\Bar", mappedBy="barVersionned", cascade={"persist"})
*/
private $barHaveVersions;
/**
* #ORM\ManyToOne(targetEntity="Application\HappyBundle\Entity\Bar", inversedBy="barHaveVersions" , cascade={"persist"})
*/
private $barVersionned;
/**
* Constructor
*/
public function __construct()
{
$this->day = new \Doctrine\Common\Collections\ArrayCollection();
$this->drink = new \Doctrine\Common\Collections\ArrayCollection();
$this->validate = false;
$this->lastUpdate = new \DateTime('now');
}
public function __toString(){
return $this->name;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* #param string $name
* #return Bar
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set address
*
* #param string $address
* #return Bar
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* #return string
*/
public function getAddress()
{
return $this->address;
}
/**
* Set postalCode
*
* #param string $postalCode
* #return Bar
*/
public function setPostalCode($postalCode)
{
$this->postalCode = $postalCode;
return $this;
}
/**
* Get postalCode
*
* #return string
*/
public function getPostalCode()
{
return $this->postalCode;
}
/**
* Set town
*
* #param string $town
* #return Bar
*/
public function setTown($town)
{
$this->town = $town;
return $this;
}
/**
* Get town
*
* #return string
*/
public function getTown()
{
return $this->town;
}
/**
* Set country
*
* #param string $country
* #return Bar
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* Get country
*
* #return string
*/
public function getCountry()
{
return $this->country;
}
/**
* Set latitude
*
* #param string $latitude
* #return Bar
*/
public function setLatitude($latitude)
{
$this->latitude = $latitude;
return $this;
}
/**
* Get latitude
*
* #return string
*/
public function getLatitude()
{
return $this->latitude;
}
/**
* Set longitude
*
* #param string $longitude
* #return Bar
*/
public function setLongitude($longitude)
{
$this->longitude = $longitude;
return $this;
}
/**
* Get longitude
*
* #return string
*/
public function getLongitude()
{
return $this->longitude;
}
/**
* Add drink
*
* #param \Application\HappyBundle\Entity\AssocBarDrink $drink
* #return Bar
*/
public function addDrink(\Application\HappyBundle\Entity\AssocBarDrink $drink)
{
$this->drink[] = $drink;
return $this;
}
/**
* Remove drink
*
* #param \Application\HappyBundle\Entity\AssocBarDrink $drink
*/
public function removeDrink(\Application\HappyBundle\Entity\AssocBarDrink $drink)
{
$this->drink->removeElement($drink);
}
/**
* Get drink
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getDrink()
{
return $this->drink;
}
/**
* Add day
*
* #param \Application\HappyBundle\Entity\AssocBarDay $day
* #return Bar
*/
public function addDay(\Application\HappyBundle\Entity\AssocBarDay $day)
{
$this->day[] = $day;
return $this;
}
/**
* Remove day
*
* #param \Application\HappyBundle\Entity\AssocBarDay $day
*/
public function removeDay(\Application\HappyBundle\Entity\AssocBarDay $day)
{
$this->day->removeElement($day);
}
/**
* Get day
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getDay()
{
return $this->day;
}
/**
* Set lastUpdate
*
* #param \DateTime $lastUpdate
* #return Bar
*/
public function setLastUpdate($lastUpdate)
{
$this->lastUpdate = $lastUpdate;
return $this;
}
/**
* Get lastUpdate
*
* #return \DateTime
*/
public function getLastUpdate()
{
return $this->lastUpdate;
}
/**
* Set validate
*
* #param boolean $validate
* #return Bar
*/
public function setValidate($validate)
{
$this->validate = $validate;
return $this;
}
/**
* Get validate
*
* #return boolean
*/
public function getValidate()
{
return $this->validate;
}
/**
* Add barHaveVersions
*
* #param \Application\HappyBundle\Entity\Bar $barHaveVersions
* #return Bar
*/
public function addBarHaveVersion(\Application\HappyBundle\Entity\Bar $barHaveVersions)
{
$this->barHaveVersions[] = $barHaveVersions;
return $this;
}
/**
* Remove barHaveVersions
*
* #param \Application\HappyBundle\Entity\Bar $barHaveVersions
*/
public function removeBarHaveVersion(\Application\HappyBundle\Entity\Bar $barHaveVersions)
{
$this->barHaveVersions->removeElement($barHaveVersions);
}
/**
* Get barHaveVersions
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getBarHaveVersions()
{
return $this->barHaveVersions;
}
/**
* Set barVersionned
*
* #param \Application\HappyBundle\Entity\Bar $barVersionned
* #return Bar
*/
public function setBarVersionned(\Application\HappyBundle\Entity\Bar $barVersionned = null)
{
$this->barVersionned = $barVersionned;
return $this;
}
/**
* Get barVersionned
*
* #return \Application\HappyBundle\Entity\Bar
*/
public function getBarVersionned()
{
return $this->barVersionned;
}
/**
* Set addressComplete
*
* #param string $addressComplete
* #return Bar
*/
public function setAddressComplete($addressComplete)
{
$this->addressComplete = $addressComplete;
return $this;
}
/**
* Get addressComplete
*
* #return string
*/
public function getAddressComplete()
{
return $this->addressComplete;
}
}
and OneToMany with this class:
<?php
namespace Application\HappyBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\ExecutionContextInterface;
/**
* AssocBarDayHappyHour
* #ORM\Table(name="assoc_bar_day")
* #ORM\Entity(repositoryClass="Application\HappyBundle\Entity\AssocBarDayRepository")
*/
class AssocBarDay
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="Application\HappyBundle\Entity\Bar", inversedBy="day" , cascade={"persist"})
*/
private $bar;
/**
* #var array
* #ORM\Column(name="day", type="array", nullable=true)
*/
private $day;
/**
* #var \DateTime
* #Assert\Time()
* #ORM\Column(name="time_start_happy_hour", type="time", nullable=true)
*/
private $timeStartHappyHour;
/**
* #var \DateTime
* #Assert\Time()
* #ORM\Column(name="time_end_happy_hour", type="time", nullable=true)
*/
private $timeEndHappyHour;
/**
* #var \DateTime
* #Assert\Time()
* #ORM\Column(name="time_bar_open", type="time", nullable=true)
*/
private $timeBarOpen;
/**
* #var \DateTime
* #Assert\Time()
* #ORM\Column(name="time_bar_close", type="time" , nullable=true)
*/
private $timeBarClose;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set timeStartHappyHour
*
* #param \DateTime $timeStartHappyHour
* #return AssocBarDay
*/
public function setTimeStartHappyHour($timeStartHappyHour)
{
$this->timeStartHappyHour = $timeStartHappyHour;
return $this;
}
/**
* Get timeStartHappyHour
*
* #return \DateTime
*/
public function getTimeStartHappyHour()
{
return $this->timeStartHappyHour;
}
/**
* Set timeEndHappyHour
*
* #param \DateTime $timeEndHappyHour
* #return AssocBarDay
*/
public function setTimeEndHappyHour($timeEndHappyHour)
{
$this->timeEndHappyHour = $timeEndHappyHour;
return $this;
}
/**
* Get timeEndHappyHour
*
* #return \DateTime
*/
public function getTimeEndHappyHour()
{
return $this->timeEndHappyHour;
}
/**
* Set timeBarOpen
*
* #param \DateTime $timeBarOpen
* #return AssocBarDay
*/
public function setTimeBarOpen($timeBarOpen)
{
$this->timeBarOpen = $timeBarOpen;
return $this;
}
/**
* Get timeBarOpen
*
* #return \DateTime
*/
public function getTimeBarOpen()
{
return $this->timeBarOpen;
}
/**
* Set timeBarClose
*
* #param \DateTime $timeBarClose
* #return AssocBarDay
*/
public function setTimeBarClose($timeBarClose)
{
$this->timeBarClose = $timeBarClose;
return $this;
}
/**
* Get timeBarClose
*
* #return \DateTime
*/
public function getTimeBarClose()
{
return $this->timeBarClose;
}
/**
* Set bar
*
* #param \Application\HappyBundle\Entity\Bar $bar
* #return AssocBarDay
*/
public function setBar(\Application\HappyBundle\Entity\Bar $bar = null)
{
$this->bar = $bar;
return $this;
}
/**
* Get bar
*
* #return \Application\HappyBundle\Entity\Bar
*/
public function getBar()
{
return $this->bar;
}
/**
* Set day
*
* #param array $day
* #return AssocBarDay
*/
public function setDay($day)
{
$this->day = $day;
return $this;
}
/**
* Get day
*
* #return array
*/
public function getDay()
{
return $this->day;
}
}
So when I post my form, the Assert of the Collection of days doesn't block when time is empty?
I put correctly the:
#Assert\Valid
Over day Collection and
#Assert\Time()
of each property of AssocBarDay
:( anyone I've got an idea?
Thanks for your help.
The reason is almost all of the validation constraints will not return invalid for empty/null values.
Just have a look at the TimeValidator's validate method ...
if (null === $value || '' === $value || $value instanceof \DateTime) {
return;
}
Therefore you will need to add the #Assert\NotBlank constraint additionally to have empty values generate a validation error for that property.
NotBlank
Validates that a value is not blank, defined as not equal to a blank
string and also not equal to null.
I tried to install PUGXMultiUserBundle, now as I did all steps I tried to load the application (only the main location: http://localhost/jpp/web/app_dev.php ), but I always get the following error:
Fatal error: Cannot instantiate abstract class JPP\UserBundle\Entity\User in C:\xampp\htdocs\JPP\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Authentication\Token\AbstractToken.php on line 155
I tried several things without success, please could you help me? Below you can find my Entity classes. I was able to create all the tables in the database with GIT. The rentity classes are located under: JPP/UserBundle/Entity. If you need more files please tell me... Thank you very much!!!
Roger
Abstract User Class:
<?php
namespace JPP\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Entity\User as BaseUser;
/**
* #ORM\Entity
* #ORM\Table(name="user")
* #ORM\InheritanceType("JOINED")
* #ORM\DiscriminatorColumn(name="type", type="string")
* #ORM\DiscriminatorMap({"userprofile" = "UserProfile", "usercompany" = "UserCompany"})
*
*/
abstract class User extends BaseUser
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
}
Class UserCompany
<?php
// src/jpp/UserBundle/Entity/User.php
namespace JPP\UserBundle\Entity;
use PUGX\MultiUserBundle\Validator\Constraints\UniqueEntity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="userCompany")
* #UniqueEntity(fields = "username", targetClass = "JPP\UserBundle\Entity\User", message="fos_user.username.already_used")
* #UniqueEntity(fields = "email", targetClass = "JPP\UserBundle\Entity\User", message="fos_user.email.already_used")
*/
class UserCompany extends User
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var integer
*
* #ORM\Column(name="usertype", type="integer")
*/
protected $userType;
/**
* #var string
*
* #ORM\Column(name="companyName", type="string", length=255)
*/
protected $companyName;
/**
* #var string
*
* #ORM\Column(name="sector", type="string", length=255)
*/
protected $sector;
/**
* #var string
*
* #ORM\Column(name="amountOfEmployees", type="string", length=255)
*/
protected $amountOfEmployees;
/**
* #var string
*
* #ORM\Column(name="turnover", type="string", length=255)
*/
protected $turnover;
/**
* #var string
*
* #ORM\Column(name="companyLink", type="string", length=255)
*/
protected $companyLink;
/**
* #var string
*
* #ORM\Column(name="facebookLink", type="string", length=255)
*/
protected $facebookLink;
/**
* #var string
*
* #ORM\Column(name="twitterLink", type="string", length=255)
*/
protected $twitterLink;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set userType
*
* #param integer $userType
* #return UserType
*/
public function setUserType($userType)
{
$this->userType = $userType;
return $this;
}
/**
* Get userType
*
* #return integer
*/
public function getUserType()
{
return $this->userType;
}
/**
* Set companyName
*
* #param string $companyName
* #return Company
*/
public function setCompanyName($companyName)
{
$this->companyName = $companyName;
return $this;
}
/**
* Get companyName
*
* #return string
*/
public function getCompanyName()
{
return $this->companyName;
}
/**
* Set sector
*
* #param string $sector
* #return Company
*/
public function setSector($sector)
{
$this->sector = $sector;
return $this;
}
/**
* Get sector
*
* #return string
*/
public function getSector()
{
return $this->sector;
}
/**
* Set amountOfEmployees
*
* #param string $amountOfEmployees
* #return Company
*/
public function setAmountOfEmployees($amountOfEmployees)
{
$this->amountOfEmployees = $amountOfEmployees;
return $this;
}
/**
* Get amountOfEmployees
*
* #return string
*/
public function getAmountOfEmployees()
{
return $this->amountOfEmployees;
}
/**
* Set turnover
*
* #param string $turnover
* #return Company
*/
public function setTurnover($turnover)
{
$this->turnover = $turnover;
return $this;
}
/**
* Get turnover
*
* #return string
*/
public function getTurnover()
{
return $this->turnover;
}
/**
* Set companyLink
*
* #param string $companyLink
* #return Company
*/
public function setCompanyLink($companyLink)
{
$this->companyLink = $companyLink;
return $this;
}
/**
* Get companyLink
*
* #return string
*/
public function getCompanyLink()
{
return $this->companyLink;
}
/**
* Set facebookLink
*
* #param string $facebookLink
* #return Company
*/
public function setFacebookLink($facebookLink)
{
$this->facebookLink = $facebookLink;
return $this;
}
/**
* Get facebookLink
*
* #return string
*/
public function getFacebookLink()
{
return $this->facebookLink;
}
/**
* Set twitterLink
*
* #param string $twitterLink
* #return Company
*/
public function setTwitterLink($twitterLink)
{
$this->twitterLink = $twitterLink;
return $this;
}
/**
* Get twitterLink
*
* #return string
*/
public function getTwitterLink()
{
return $this->twitterLink;
}
}
Class UserProfile
// src/jpp/UserBundle/Entity/User.php
namespace JPP\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use PUGX\MultiUserBundle\Validator\Constraints\UniqueEntity;
/**
* #ORM\Entity
* #ORM\Table(name="userProfile")
* #UniqueEntity(fields = "username", targetClass = "JPP\UserBundle\Entity\User", message="fos_user.username.already_used")
* #UniqueEntity(fields = "email", targetClass = "JPP\UserBundle\Entity\User", message="fos_user.email.already_used")
*/
class UserProfile extends User
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var integer
*
* #ORM\Column(name="usertype", type="integer")
*/
protected $userType;
/**
* #ORM\Column(type="string", length=255)
*
*/
protected $foreName;
/**
* #ORM\Column(type="string", length=255)
*
*/
protected $surName;
/**
* #ORM\Column(type="string", length=255)
*
*/
protected $street;
/**
* #ORM\Column(type="string", length=255)
*
*/
protected $plz;
/**
* #ORM\Column(type="string", length=255)
*
*/
protected $place;
/**
* #ORM\Column(type="string", length=255)
*
*/
protected $phone;
/**
* #ORM\Column(type="string", length=255)
*
*/
protected $mobile;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set userType
*
* #param integer $userType
* #return UserType
*/
public function setUserType($userType)
{
$this->userType = $userType;
return $this;
}
/**
* Get userType
*
* #return integer
*/
public function getUserType()
{
return $this->userType;
}
/**
* Set foreName
*
* #param string $foreName
* #return ForeName
*/
public function setForeName($foreName)
{
$this->foreName = $foreName;
return $this;
}
/**
* Get foreName
*
* #return string
*/
public function getForeName()
{
return $this->foreName;
}
/**
* Set surName
*
* #param string $surName
* #return SurName
*/
public function setSurName($surName)
{
$this->surName = $surName;
return $this;
}
/**
* Get surName
*
* #return string
*/
public function getSurName()
{
return $this->surName;
}
/**
* Set street
*
* #param string $street
* #return Street
*/
public function setStreet($street)
{
$this->street = $street;
return $this;
}
/**
* Get street
*
* #return string
*/
public function getStreet()
{
return $this->street;
}
/**
* Set plz
*
* #param string $plz
* #return PLZ
*/
public function setPlz($plz)
{
$this->plz = $plz;
return $this;
}
/**
* Get plz
*
* #return string
*/
public function getPlz()
{
return $this->plz;
}
/**
* Set place
*
* #param string $place
* #return Place
*/
public function setPlace($place)
{
$this->place = $place;
return $this;
}
/**
* Get place
*
* #return string
*/
public function getPlace()
{
return $this->place;
}
/**
* Set phone
*
* #param string $phone
* #return Phone
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* Get phone
*
* #return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set mobile
*
* #param string $mobile
* #return Mobile
*/
public function setMobile($mobile)
{
$this->mobile = $mobile;
return $this;
}
/**
* Get mobile
*
* #return string
*/
public function getMobile()
{
return $this->mobile;
}
//public function __construct()
//{
// parent::__construct();
// your own logic
//}
}
The error says:
Fatal error: Cannot instantiate abstract class JPP\UserBundle\Entity\User in C:\xampp\htdocs\JPP\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Authentication\Token\AbstractToken.php on line 155
It means that Symfony tries to instantiante your User class (e.g. new User()) but fails because this class is abstract. So, just remove abstract definition.
Replace
abstract class User extends BaseUser
with
class User extends BaseUser