Im working in a symfony3 project where i have a onetomany relation to upload multiple files with VICH UPLOADER, and save each file as separated entity.
First entity is "Message", and has a onetomany relation with "MessageAttachment".
Message entity
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var CourseEdition
*
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\CourseEdition")
* #ORM\JoinColumn(name="edition_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
private $edition;
/**
* #var Message
*
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Message", inversedBy="childs", cascade={"persist", "remove"})
* #ORM\JoinColumn(name="parent_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
*/
private $parent;
/**
* #var User
*
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\User", cascade={"persist", "remove"})
* #ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
private $user;
/**
* #var string
*
* #ORM\Column(name="subject", type="string", length=255)
*/
private $subject;
/**
* #var string
*
* #ORM\Column(name="body", type="text")
*/
private $body;
/**
* #var \DateTime
*
* #ORM\Column(name="created_at", type="datetime")
* #Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* #var ArrayCollection
*
* #ORM\OneToMany(targetEntity="AppBundle\Entity\Message", mappedBy="parent", orphanRemoval=true)
*/
private $childs;
/**
* #var ArrayCollection
*
* #ORM\OneToMany(targetEntity="AppBundle\Entity\MessageAttachment", mappedBy="message", orphanRemoval=true, cascade={"persist", "remove"})
* #Assert\Valid()
*/
private $attachments;
/**
* #var ArrayCollection
*
* #ORM\OneToMany(targetEntity="AppBundle\Entity\MessageUser", mappedBy="message", orphanRemoval=true, cascade={"persist"})
*/
private $recipients;
public function __construct()
{
$this->childs = new ArrayCollection();
$this->attachments = new ArrayCollection();
$this->recipients = new ArrayCollection();
}
/**
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* #param CourseEdition $edition
*
* #return Message
*/
public function setEdition($edition)
{
$this->edition = $edition;
return $this;
}
/**
* #return CourseEdition
*/
public function getEdition()
{
return $this->edition;
}
/**
* #param Message $parent
*
* #return Message
*/
public function setParent($parent)
{
$this->parent = $parent;
return $this;
}
/**
* #return Message
*/
public function getParent()
{
return $this->parent;
}
/**
* #param User $user
*
* #return Message
*/
public function setUser($user)
{
$this->user = $user;
return $this;
}
/**
* #return User
*/
public function getUser()
{
return $this->user;
}
/**
* #param string $subject
*
* #return Message
*/
public function setSubject($subject)
{
$this->subject = $subject;
return $this;
}
/**
* #return string
*/
public function getSubject()
{
return $this->subject;
}
/**
* #param string $body
*
* #return Message
*/
public function setBody($body)
{
$this->body = $body;
return $this;
}
/**
* #return string
*/
public function getBody()
{
return $this->body;
}
/**
* #param \DateTime $createdAt
*
* #return Message
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* #return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* #param MessageAttachment $attachment
*
* #return Message
*/
public function addAttachment($attachment)
{
$this->attachments->add($attachment);
$attachment->setMessage($this);
return $this;
}
/**
* #param MessageAttachment $attachment
*
* #return Message
*/
public function removeAttachment($attachment)
{
$this->attachments->removeElement($attachment);
$attachment->setMessage(null);
return $this;
}
/**
* #return \Doctrine\Common\Collections\Collection
*/
public function getAttachments()
{
return $this->attachments;
}
/**
* #param Message $message
*
* #return Message
*/
public function addChild($message)
{
$this->childs->add($message);
$message->setParent($this);
return $this;
}
/**
* #param Message $message
*
* #return Message
*/
public function removeChild($message)
{
$this->childs->removeElement($message);
$message->setParent(null);
return $this;
}
/**
* #return ArrayCollection
*/
public function getChilds()
{
return $this->childs;
}
/**
* #param NoticeUser $recipient
*
* #return Message
*/
public function addRecipient($recipient)
{
$this->recipients->add($recipient);
return $this;
}
/**
* #param NoticeUser $recipient
*
* #return Message
*/
public function removeRecipient($recipient)
{
$this->recipients->removeElement($recipient);
return $this;
}
/**
* #return ArrayCollection
*/
public function getRecipients()
{
return $this->recipients;
}
MessageAttachment Entity:
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var Message
*
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Message", inversedBy="attachments", cascade={"persist", "remove"})
* #ORM\JoinColumn(name="message_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
private $message;
/**
* #var Filesys
*
* #Vich\UploadableField(mapping="doc_message_attach",fileNameProperty="name")
*/
private $file;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="realname", type="string", length=255)
*/
private $realname;
/**
* #var int
*
* #ORM\Column(name="size", type="integer")
*/
private $size;
/**
* #var string
*
* #ORM\Column(name="mime_type", type="string", length=100)
*/
private $mimeType;
/**
* #var \DateTime
*
* #ORM\Column(name="created_at", type="datetime")
* #Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* #param Message $message
*
* #return MessageAttachment
*/
public function setMessage($message)
{
$this->message = $message;
return $this;
}
/**
* #return Message
*/
public function getMessage()
{
return $this->message;
}
/**
* #param Filesys|\Symfony\Component\HttpFoundation\File\UploadedFile $file
*
* #return MessageAttachment
*/
public function setFile($file = null)
{
$this->file = $file;
if ($file) {
$this->size = $file->getSize();
$this->mimeType = $file->getMimeType();
$this->realname = $file->getClientOriginalName();
}
return $this;
}
/**
* #return Filesys|null
*/
public function getFile()
{
return $this->file;
}
/**
* #param string $name
*
* #return MessageAttachment
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* #param integer $size
*
* #return MessageAttachment
*/
public function setSize($size)
{
$this->size = $size;
return $this;
}
/**
* #return int
*/
public function getSize()
{
return $this->size;
}
/**
* #param string $mimeType
*
* #return MessageAttachment
*/
public function setMimeType($mimeType)
{
$this->mimeType = $mimeType;
return $this;
}
/**
* #return string
*/
public function getMimeType()
{
return $this->mimeType;
}
/**
* #param \DateTime $createdAt
*
* #return MessageAttachment
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* #return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set realname
*
* #param string $realname
*
* #return MessageAttachment
*/
public function setRealname($realname)
{
$this->realname = $realname;
return $this;
}
/**
* Get realname
*
* #return string
*/
public function getRealname()
{
return $this->realname;
}
**As you can see, in setFile() in MessageAttachments, im trying to retrieve original file name, and save it. Vich uploader can do it with annotations, but im not working in php 7 !
Everything is working ok, filesize and mimetypes are being saved correctly, except saving original name.**
This is the error symfony shows me:
[Tue Oct 17 11:58:19.031167 2017] [:error] [pid 9076:tid 1816] [client 127.0.0.1:53731] PHP Fatal error: Call to undefined method Symfony\Component\HttpFoundation\File\File::getClientOriginalName() in C:\xampp\htdocs\mindway2\src\AppBundle\Entity\MessageAttachment.php on line 121, referer: http://mindway.dev/messages/new
Any idea? i cant find why!
The real filename needs to be shown, and i need it to rename files for downloading.
Finally, i have decided to do it in the way i dont like, in controller, before persist entities:
foreach($message->getAttachments() as $attachfile)
{
$attachfile->setRealname($attachfile->getFile()->getClientOriginalName());
}
It says it's looking in Symfony\Component\HttpFoundation\File\ File and it doesn't exist in that class --that's true. The method getClientOriginalName is in Symfony\Component\HttpFoundation\File\ UploadedFile.
Does your use statement say File or UploadedFile? If it's not UploadedFile, change it and see what happens.
Related
I wanted to index some data from a associated entity of the main entity which I already have an index for. My mapping rules are as below and I have given the 2 entities below too. My problem is I am getting OutOfMemoryException while trying to populate the index. bin/console fos:elastica:populate --index=sales_rule
Index configuration
sales_rule:
client: default
use_alias: true
types:
sales_rule:
mappings:
id: {type: integer}
name:
description:
salesCoupons:
type: nested
properties:
code:
persistence:
driver: orm
model: MyProject\MyBundle\Entity\SalesRule
provider:
batch_size: 100
listener:
Entities
/**
* #ORM\Table(name="sales_rule")
* #ORM\Entity(repositoryClass="MyProject\MyBundle\Repository\SalesRuleRepository")
*/
class SalesRule
{
/**
* #var int
*
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue
*/
private $id;
/**
* #var string
*
* #ORM\Column(type="string")
*/
private $name;
/**
* #var string
*
* #ORM\Column(type="text")
*/
private $description;
/**
* #var int
*
* #ORM\Column(type="integer", nullable=true)
*/
private $usageLimit;
/**
* #var SalesCoupon[]|ArrayCollection
*
* #ORM\OneToMany(targetEntity="SalesCoupon", mappedBy="salesRule")
*/
private $salesCoupons;
public function __construct()
{
$this->salesCoupons = new ArrayCollection();
}
/**
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* #return int
*/
public function getUsageLimit()
{
return $this->usageLimit;
}
/**
* #return int
*/
public function getUsagePerCustomer()
{
return $this->usagePerCustomer;
}
/**
* #param string $description
* #return SalesRule
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* #param string $name
* #return SalesRule
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* #param int $usageLimit
* #return SalesRule
*/
public function setUsageLimit($usageLimit)
{
$this->usageLimit = $usageLimit;
return $this;
}
/**
* #return SalesCoupon[]|ArrayCollection
*/
public function getSalesCoupons()
{
return $this->salesCoupons;
}
/**
* #param ArrayCollection $salesCoupons
*/
public function setSalesCoupons(ArrayCollection $salesCoupons)
{
$this->salesCoupons = $salesCoupons;
}
}
/**
* #ORM\Table(name="sales_coupon")
* #ORM\Entity(repositoryClass="MyProject\MyBundle\Repository\SalesCouponRepository")
*/
class SalesCoupon
{
/**
* #var int
*
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue
*/
private $id;
/**
* #var SalesRule
*
* #Serializer\Exclude
*
* #ORM\ManyToOne(targetEntity="SalesRule", inversedBy="salesCoupons")
* #ORM\JoinColumn(nullable=false)
*/
private $salesRule;
/**
* #var \DateTime
*
* #ORM\Column(type="datetime", nullable=true)
*/
private $fromDate;
/**
* #var \DateTime
*
* #ORM\Column(type="datetime", nullable=true)
*/
private $toDate;
/**
* #var string
*
* #ORM\Column(nullable=true)
*/
private $code;
/**
* #var int
*
* #Assert\Range(min=0)
*
* #ORM\Column(type="integer", nullable=true)
*/
private $usageLimit;
public function __construct()
{
$this->salesCouponCustomers = new ArrayCollection();
}
/**
* #return string
*/
public function getCode()
{
return $this->code;
}
/**
* #return \DateTime
*/
public function getFromDate()
{
return $this->fromDate;
}
/**
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* #return \Unity\CmsBundle\Entity\SalesRule
*/
public function getSalesRule()
{
return $this->salesRule;
}
/**
* #return \DateTime
*/
public function getToDate()
{
return $this->toDate;
}
/**
* #param string $code
* #return SalesCoupon
*/
public function setCode($code)
{
$this->code = $code;
return $this;
}
/**
* #param \DateTime $fromDate
* #return SalesCoupon
*/
public function setFromDate($fromDate)
{
$this->fromDate = $fromDate;
return $this;
}
/**
* #param \Unity\CmsBundle\Entity\SalesRule $salesRule
* #return SalesCoupon
*/
public function setSalesRule(SalesRule $salesRule)
{
$this->salesRule = $salesRule;
return $this;
}
/**
* #param \DateTime $toDate
* #return SalesCoupon
*/
public function setToDate($toDate)
{
$this->toDate = $toDate;
return $this;
}
}
Can you try set limit memory unlimit.
php -d memory_limit=-1 bin/console fos:elastica:populate --index=sales_rule
I have a Portfolio entity which is working well to create or update but I can't delete it. Symfony throws this error:
Entity matthieu-appriou is not managed. An entity is managed if its
fetched from the database or registered as new through
EntityManager#persist
Here is my entity:
<?php
namespace CreasensoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use SensoBundle\Entity\Talent;
use Doctrine\Common\Collections\ArrayCollection;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Translatable\Translatable;
use JMS\Serializer\Annotation\MaxDepth;
use JMS\Serializer\Annotation\Exclude;
/**
* Portfolio
*
* #ORM\Entity
* #ORM\Table(name="portfolio")
* #ORM\Entity(repositoryClass="CreasensoBundle\Repository\PortfolioRepository")
*/
class Portfolio
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var bool
*
* #ORM\Column(name="visible", type="boolean", nullable=true)
*/
private $visible;
/**
* #Exclude
* #ORM\OneToOne(targetEntity="SensoBundle\Entity\Talent", cascade={"persist", "remove"}, inversedBy="portfolio")
* #ORM\JoinColumn(nullable=true, onDelete="SET NULL")
*/
private $talent;
/**
* #Exclude
* #ORM\OneToOne(targetEntity="SensoBundle\Entity\Image", cascade={"persist", "remove"})
* #ORM\JoinColumn(nullable=true, onDelete="SET NULL")
*/
private $image;
/**
* #var string
*
* #ORM\Column(name="folio_label", type="string", length=400, nullable=true)
* #Gedmo\Translatable
*/
private $folioLabel;
/**
* #var string
*
* #ORM\Column(name="main_customers", type="string", length=400, nullable=true)
*/
private $mainCustomers;
/**
* #var string
*
* #ORM\Column(name="main_agencies", type="string", length=400, nullable=true)
*/
private $mainAgencies;
/**
* #var string
*
* #ORM\Column(name="publications", type="string", length=700, nullable=true)
*/
private $publications;
/**
* #var string
*
* #ORM\Column(name="description_title", type="string", length=400, nullable=true)
* #Gedmo\Translatable
*/
private $descriptionTitle;
/**
* #var string
*
* #ORM\Column(name="description_content", type="text", nullable=true)
* #Gedmo\Translatable
*/
private $descriptionText;
/**
* #MaxDepth(2)
* #ORM\ManyToMany(targetEntity="SensoBundle\Entity\Expertise", cascade={"persist"})
*/
private $expertises;
/**
* #var \DateTime $created
*
* #Gedmo\Timestampable(on="create")
* #ORM\Column(type="datetime")
*/
private $created;
/**
* #var \DateTime $updated
*
* #Gedmo\Timestampable(on="update")
* #ORM\Column(type="datetime")
*/
private $updated;
/**
* #var \DateTime $updated
*
* #ORM\Column(type="datetime", nullable=true)
*/
private $mostRecentProjectDate;
/**
* #var \DateTime $featuredTime
* #ORM\Column(type="datetime", nullable=true)
*/
private $featuredTime;
/**
* #var \DateTime $submissionTime
* #ORM\Column(type="datetime", nullable=true)
*/
private $submissionTime;
/**
* #Gedmo\Locale
*/
protected $locale;
public function __construct()
{
$this->setVisible(false);
$this->expertises = new ArrayCollection();
}
public function __toString() {
return $this->getSlug();
}
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
public function getSlug()
{
return $this->getTalent()->getSlug();
}
/**
* Set visible
*
* #param boolean $visible
*
* #return Portfolio
*/
public function setVisible($visible)
{
$this->visible = $visible;
return $this;
}
/**
* Get visible
*
* #return bool
*/
public function getVisible()
{
return $this->visible;
}
/**
* #return mixed
*/
public function getTalent()
{
return $this->talent;
}
/**
* #param mixed $talent
*/
public function setTalent($talent)
{
$this->talent = $talent;
$talent->setPortfolio($this);
}
/**
* #return mixed
*/
public function getImage()
{
return $this->image;
}
/**
* #param mixed $image
*/
public function setImage($image)
{
if ($image) {
$image->setParentType('portfolio');
}
$this->image = $image;
}
/**
* #return string
*/
public function getMainCustomers()
{
return $this->mainCustomers;
}
/**
* #param string $mainCustomers
*/
public function setMainCustomers($mainCustomers)
{
$this->mainCustomers = $mainCustomers;
}
/**
* #return string
*/
public function getMainAgencies()
{
return $this->mainAgencies;
}
/**
* #param string $mainAgencies
*/
public function setMainAgencies($mainAgencies)
{
$this->mainAgencies = $mainAgencies;
}
/**
* #return string
*/
public function getDescriptionTitle()
{
return $this->descriptionTitle;
}
/**
* #param string $descriptionTitle
*/
public function setDescriptionTitle($descriptionTitle)
{
$this->descriptionTitle = $descriptionTitle;
}
/**
* #return string
*/
public function getDescriptionText()
{
return $this->descriptionText;
}
/**
* #param string $descriptionText
*/
public function setDescriptionText($descriptionText)
{
$this->descriptionText = $descriptionText;
}
public function addExpertise($expertise)
{
$this->expertises[] = $expertise;
return $this;
}
public function removeExpertise($expertise)
{
$this->expertises->removeElement($expertise);
}
public function getExpertises()
{
return $this->expertises;
}
public function setExpertises($expertises)
{
$this->expertises = $expertises;
}
/**
* #return mixed
*/
public function getCreated()
{
return $this->created;
}
/**
* #param mixed $created
*/
public function setCreated($created)
{
$this->created = $created;
}
/**
* #return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* #param \DateTime $updated
*/
public function setUpdated($updated)
{
$this->updated = $updated;
}
/**
* #return \DateTime
*/
public function getFeaturedTime()
{
return $this->featuredTime;
}
/**
* #param \DateTime $featuredTime
*/
public function setFeaturedTime($featuredTime)
{
$this->featuredTime = $featuredTime;
}
/**
* #return string
*/
public function getPublications()
{
return $this->publications;
}
/**
* #param string $publications
*/
public function setPublications($publications)
{
$this->publications = $publications;
}
/**
* #return mixed
*/
public function getSubmissionTime()
{
return $this->submissionTime;
}
/**
* #param mixed $submissionTime
*/
public function setSubmissionTime($submissionTime)
{
$this->submissionTime = $submissionTime;
}
/**
* #return string
*/
public function getFolioLabel()
{
return $this->folioLabel;
}
/**
* #param string $folioLabel
*/
public function setFolioLabel($folioLabel)
{
$this->folioLabel = $folioLabel;
}
public function getType()
{
return 'portfolio';
}
/**
* #return \DateTime
*/
public function getMostRecentProjectDate()
{
return $this->mostRecentProjectDate;
}
/**
* #param \DateTime $mostRecentProjectDate
*/
public function setMostRecentProjectDate($mostRecentProjectDate)
{
$this->mostRecentProjectDate = $mostRecentProjectDate;
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
}
And here is the code sample I use to reproduce this error:
<?php
// namespace and use ...
/**
* Tool controller.
*
* #Route("/admin/test")
*/
class TestController extends Controller
{
/**
*
* #Route("/testTwo", name="testTwo")
* #Method({"GET", "POST"})
*/
public function indexTwoAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$pr = $this->get('creasenso.portfolio_repo');
$p = $pr->find(32);
$em->remove($p);
$em->flush();
return new Response("<html><head></head><body><hr />Done</body></html>");
}
}
Here is the repository linked to this entity:
<?php
namespace CreasensoBundle\Repository;
use Doctrine\ORM\EntityRepository;
/**
* PortfolioRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class PortfolioRepository extends EntityRepository
{
protected $qb;
public function init()
{
$this->qb = $this->createQueryBuilder('p');
}
public function isVisible()
{
$this->qb
->andWhere('p.visible = :visible')
->setParameter(':visible', 1);
}
public function getAllPublicPortfolioCount()
{
$this->init();
$this->isVisible();
$this->qb->select('COUNT(p)');
return $this->qb->getQuery()->getSingleScalarResult();
}
public function getQueryBuilder()
{
return $this->qb;
}
}
Do you have any clue about this behavior? Thank you very much.
You are getting your repository directly from the service container when you should be getting it from your EntityManager through getRepository().
You are not loading your entity from the entityManager that you flush so it is not managed
In editAction method of controller I tried to edit existed entities in class table inheritance.
But after form submit I get error:
Neither the property "id" nor one of the methods
"addId()"/"removeId()", "setId()", "id()", "__set()" or "__call()"
exist and have public access in class "AdBundle\Entity\AdFlat".
Why AdFlat entity not extended of AdBase entity?
Base entity:
<?php
namespace AdBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* AdBase
*
* #ORM\Table(name="ad_base")
* #ORM\Entity(repositoryClass="AdBundle\Repository\AdBaseRepository")
* #ORM\HasLifecycleCallbacks()
* #ORM\InheritanceType("JOINED")
* #ORM\DiscriminatorColumn(name="discr", type="string")
* #ORM\DiscriminatorMap({
"flat" = "AdFlat"
* })
*/
abstract class AdBase
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var string
*
* #ORM\Column(name="author", type="string", length=255)
*/
private $author;
/**
* #ORM\ManyToOne(targetEntity="AdBundle\Entity\AdCategory")
*/
private $category;
/**
* #ORM\Column(type="string")
* #Assert\NotBlank(message="Field Location should not be blank")
*/
private $location;
/**
* #var string
*
* #ORM\Column(name="title", type="string", length=255)
* #Assert\NotBlank(message="Not specified Title")
*/
private $title;
/**
* #var string
*
* #ORM\Column(name="description", type="text", nullable=true)
* #Assert\NotBlank(message="Not specified Description")
*/
private $description;
/**
* #ORM\OneToMany(targetEntity="AdBundle\Entity\AdPhoto", mappedBy="ad")
*/
private $photos;
/**
* #ORM\Column(type="float")
* #Assert\NotBlank()
*/
private $price;
/**
* #ORM\ManyToOne(targetEntity="AdBundle\Entity\AdPriceType")
*/
private $priceType;
/**
* #var \DateTime
*
* #ORM\Column(name="createdAt", type="datetime")
*/
private $createdAt;
/**
* #var string
*
* #ORM\Column(name="updatedAt", type="datetime")
*/
private $updatedAt;
/**
* #var bool
*
* #ORM\Column(name="visible", type="boolean")
*/
private $visible = false;
/**
* #ORM\Column(type="boolean")
*/
private $active = true;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set author
*
* #param string $author
*
* #return AdBase
*/
public function setAuthor($author)
{
$this->author = $author;
return $this;
}
/**
* Get author
*
* #return string
*/
public function getAuthor()
{
return $this->author;
}
/**
* #return mixed
*/
public function getCategory()
{
return $this->category;
}
/**
* #param mixed $category
*/
public function setCategory($category)
{
$this->category = $category;
}
/**
* #return mixed
*/
public function getLocation()
{
return $this->location;
}
/**
* #param mixed $location
*/
public function setLocation($location)
{
$this->location = $location;
}
/**
* Set title
*
* #param string $title
*
* #return AdBase
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set description
*
* #param string $description
*
* #return AdBase
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set photos
*
* #param string $photos
*
* #return AdBase
*/
public function setPhotos($photos)
{
$this->photos = $photos;
return $this;
}
/**
* Get photos
*
* #return string
*/
public function getPhotos()
{
return $this->photos;
}
/**
* #return mixed
*/
public function getPrice()
{
return $this->price;
}
/**
* #param mixed $price
*/
public function setPrice($price)
{
$this->price = $price;
}
/**
* #return mixed
*/
public function getPriceType()
{
return $this->priceType;
}
/**
* #param mixed $priceType
*/
public function setPriceType($priceType)
{
$this->priceType = $priceType;
}
/**
* Set createdAt
*
* #param \DateTime $createdAt
*
* #return AdBase
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* #return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set updatedAt
*
* #param string $updatedAt
*
* #return AdBase
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* #return string
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Set visible
*
* #param boolean $visible
*
* #return AdBase
*/
public function setVisible($visible)
{
$this->visible = $visible;
return $this;
}
/**
* Get visible
*
* #return bool
*/
public function getVisible()
{
return $this->visible;
}
/**
* #return mixed
*/
public function getActive()
{
return $this->active;
}
/**
* #param mixed $active
*/
public function setActive($active)
{
$this->active = $active;
}
/**
* #ORM\PrePersist()
*/
public function prePersist()
{
$this->author = 'voodoo';
$this->createdAt = new \DateTime('now', new \DateTimeZone('UTC'));
$this->updatedAt = new \DateTime('now', new \DateTimeZone('UTC'));
$this->location = 'Donetsk';
}
/**
* #ORM\PreUpdate()
*/
public function preUpdate()
{
$this->updatedAt = new \DateTime('now', new \DateTimeZone('UTC'));
}
}
Extended entity:
<?php
namespace AdBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* AdFlat
*
* #ORM\Table(name="ad_flat")
* #ORM\Entity(repositoryClass="AdBundle\Repository\AdFlatRepository")
*/
class AdFlat extends AdBase
{
/**
* #var integer
*
* #ORM\Column(type="integer")
* #Assert\NotBlank(message="ad_flat.rooms.not_blank")
*/
private $rooms;
/**
* #var float
*
* #ORM\Column(name="square", type="float", nullable=true)
*/
private $square;
/**
* #var float
*
* #ORM\Column(name="liveSquare", type="float", nullable=true)
*/
private $liveSquare;
/**
* #var float
*
* #ORM\Column(type="float", nullable=true)
*/
private $kitchenSquare;
/**
* #var int
*
* #ORM\Column(name="floor", type="integer")
*/
private $floor;
/**
* #var int
*
* #ORM\Column(name="floors", type="integer")
*/
private $floors;
/**
* #var string
*
* #ORM\ManyToOne(targetEntity="AdBundle\Entity\AdWallType")
*/
private $wallType;
/**
* #ORM\ManyToOne(targetEntity="AdBundle\Entity\AdWCType")
*/
private $wcType;
/**
* #return mixed
*/
public function getRooms()
{
return $this->rooms;
}
/**
* #param mixed $rooms
*/
public function setRooms($rooms)
{
$this->rooms = $rooms;
}
/**
* Set square
*
* #param float $square
*
* #return AdFlat
*/
public function setSquare($square)
{
$this->square = $square;
return $this;
}
/**
* Get square
*
* #return float
*/
public function getSquare()
{
return $this->square;
}
/**
* Set liveSquare
*
* #param float $liveSquare
*
* #return AdFlat
*/
public function setLiveSquare($liveSquare)
{
$this->liveSquare = $liveSquare;
return $this;
}
/**
* Get liveSquare
*
* #return float
*/
public function getLiveSquare()
{
return $this->liveSquare;
}
/**
* #return float
*/
public function getKitchenSquare()
{
return $this->kitchenSquare;
}
/**
* #param float $kitchenSquare
*/
public function setKitchenSquare($kitchenSquare)
{
$this->kitchenSquare = $kitchenSquare;
}
/**
* Set floor
*
* #param integer $floor
*
* #return AdFlat
*/
public function setFloor($floor)
{
$this->floor = $floor;
return $this;
}
/**
* Get floor
*
* #return int
*/
public function getFloor()
{
return $this->floor;
}
/**
* Set floors
*
* #param integer $floors
*
* #return AdFlat
*/
public function setFloors($floors)
{
$this->floors = $floors;
return $this;
}
/**
* Get floors
*
* #return int
*/
public function getFloors()
{
return $this->floors;
}
/**
* Set wallType
*
* #param string $wallType
*
* #return AdFlat
*/
public function setWallType($wallType)
{
$this->wallType = $wallType;
return $this;
}
/**
* Get wallType
*
* #return string
*/
public function getWallType()
{
return $this->wallType;
}
/**
* Set wcType
*
* #param string $wcType
*
* #return AdFlat
*/
public function setWcType($wcType)
{
$this->wcType = $wcType;
return $this;
}
/**
* Get wcType
*
* #return string
*/
public function getWcType()
{
return $this->wcType;
}
}
In controller:
public function editAction(Request $request)
{
$adId = $request->get('id');
if (!$adId) {
return $this->renderError('Unknown Ad');
}
$adEntity = $this->getDoctrine()->getRepository('AdBundle:AdBase')->find($adId);
if (null === $adEntity) {
return $this->renderError('Unknown Ad');
}
$reflection = new \ReflectionClass($adEntity);
$adForm = $this->getForm($reflection->getShortName());
$form = $this->createForm($adForm, $adEntity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($adEntity);
$em->flush();
return $this->redirectToRoute('ad_bundle_ad_view', array(
'id' => $adEntity->getId()
));
}
return $this->render('AdBundle:Ad:edit-ad-flat.html.twig', array(
'form' => $form->createView()
));
}
private function renderError($message = '')
{
return $this->render('::error.html.twig', array(
'error' => $message
));
}
private function getEntity($className)
{
$entityName = 'AdBundle\Entity\\' . $className;
return new $entityName();
}
private function getForm($className)
{
$formName = 'AdBundle\Form\Type\\' . $className . 'Type';
return new $formName();
}
The error message simply states that you are missing a way to set the entity's $id property. It doesn't tell you anything about the class not extending the base class. However, your base class only defines a getter method for the $id property but no setter method.
Doctrine Entities work as POPOs (Plain Old PHP Objects). To achieve extending correctly you need to work with the MappedSuperClass here is an example
I created a Twig extension, registered it in services, but im getting an error:
This is the extension:
<?php
// src/AppBundle/Twig/AppExtension.php
namespace Mp\ShopBundle\twig;
class AppExtension extends \Twig_Extension
{
public function getFunctions()
{
return array(
'getTotalPrice' => new \Twig_Function_Method($this, 'getTotalPrice'));
}
public function getTotalPrice(Items $items)
{
$total = 0;
foreach($items as $item){
$total += $item->getPrice();
}
return $total;
}
public function getName()
{
return 'app_extension';
}
}
Services:
services:
app.twig_extension:
class: Mp\ShopBundle\twig\AppExtension
public: false
tags:
- { name: twig.extension }
Now i want to count the sum of products with my extension like this:
{% for item in product %}
<td> ${{getTotalPrice(item)}}.00</td>
{% endfor %}
But i get this error:
An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Argument 1 passed to Mp\ShopBundle\twig\AppExtension::getTotalPrice() must be an instance of Mp\ShopBundle\twig\Items, instance of Mp\ShopBundle\Entity\Product given, called in C:\wamp\www\Digidis\tree\app\cache\dev\twig\b4\5d\b2cbf04f86aeef591812f9721d41a678d3fc5dbbd3aae638883d71c26af0.php on line 175 and defined") in MpShopBundle:Frontend:product_summary.html.twig at line 92.
Product:
<?php
namespace Mp\ShopBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Sonata\ClassificationBundle\Model\TagInterface;
use Sonata\ClassificationBundle\Model\Tag;
/**
* Product
*
* #ORM\Table(name="product", indexes={#ORM\Index(name="product_type_id", columns={"product_type_id"})})
* #ORM\Entity
*/
class Product
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="model", type="string", length=255, nullable=true)
*/
private $model;
/**
* #var \Mp\ShopBundle\Entity\ProductType
*
* #ORM\ManyToOne(targetEntity="Mp\ShopBundle\Entity\ProductType")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="product_type_id", referencedColumnName="id")
* })
*/
private $productType;
/**
* #var \Mp\ShopBundle\Entity\ProductLanguageData
*
* #ORM\OneToMany(targetEntity="ProductLanguageData", mappedBy="product", cascade={"persist"}, orphanRemoval=true)
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="id", referencedColumnName="product_id")
* })
*/
private $translations;
/**
* #var string
*
* #ORM\Column(name="admin_title", type="string", length=255, nullable=true)
*/
private $admin_title;
protected $tags;
/**
* #var \Application\Sonata\ClassificationBundle\Entity\Category
*
* #ORM\ManyToOne(targetEntity="Application\Sonata\ClassificationBundle\Entity\Category")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="category_id", referencedColumnName="id")
* })
*/
private $category;
/**
* #var \Application\Sonata\ClassificationBundle\Entity\Category
*
* #ORM\ManyToOne(targetEntity="Application\Sonata\ClassificationBundle\Entity\Category")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="subcategory_id", referencedColumnName="id")
* })
*/
private $subcategory;
/**
* #var \Application\Sonata\ClassificationBundle\Entity\Collection
*
* #ORM\ManyToOne(targetEntity="Application\Sonata\ClassificationBundle\Entity\Collection")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="manufacturer_id", referencedColumnName="id")
* })
*/
private $manufacturer;
/**
* #var boolean
*
* #ORM\Column(name="status", type="boolean")
*/
private $status;
/**
* #ORM\Column(name="created_at", type="datetime")
*/
private $created_at;
/**
* #ORM\Column(name="updated_at", type="datetime")
*/
private $updated_at;
/**
* #ORM\Column(name="pc", type="decimal", precision=10, scale=2, nullable=true)
*/
private $pc;
/**
* #ORM\Column(name="value", type="decimal", precision=10, scale=2, nullable=true)
*/
private $value;
/**
* #ORM\Column(name="discount", type="decimal", precision=10, scale=2, nullable=true)
*/
private $discount;
/**
* #ORM\Column(name="base", type="decimal", precision=10, scale=2, nullable=true)
*/
private $base;
/**
* #ORM\Column(name="price", type="decimal", precision=10, scale=2, nullable=true)
*/
private $price;
/**
* #ORM\Column(name="stock", type="integer", nullable=true)
*/
private $stock;
/**
* #ORM\Column(name="map", type="string", length=255, nullable=true)
*/
private $map;
/**
* #ORM\Column(name="feature1", type="string", length=255, nullable=true)
*/
private $feature1;
/**
* #ORM\Column(name="feature2", type="string", length=255, nullable=true)
*/
private $feature2;
/**
* #ORM\Column(name="feature3", type="string", length=255, nullable=true)
*/
private $feature3;
/**
* #ORM\Column(name="feature4", type="string", length=255, nullable=true)
*/
private $feature4;
/**
* #ORM\Column(name="feature5", type="string", length=255, nullable=true)
*/
private $feature5;
/**
* #ORM\Column(name="feature6", type="string", length=255, nullable=true)
*/
private $feature6;
/**
* #ORM\Column(name="feature7", type="string", length=255, nullable=true)
*/
private $feature7;
/**
* #ORM\Column(name="feature8", type="string", length=255, nullable=true)
*/
private $feature8;
/**
* #var boolean
*
* #ORM\Column(name="published", type="boolean", nullable=true)
*/
private $published;
/**
* #ORM\Column(name="url_marketing", type="string", length=255, nullable=true)
*/
private $url_marketing;
/**
* #ORM\Column(name="cesion_tienda", type="string", length=255, nullable=true)
*/
private $cesion_tienda;
/**
* #ORM\Column(name="google", type="string", length=255, nullable=true)
*/
private $google;
/**
* #ORM\Column(name="provider_reference", type="string", length=255, nullable=true)
*/
private $provider_reference;
private $gallery;
/**
* #ORM\Column(name="vat", type="string", length=255, nullable=true)
*/
private $vat;
private $provider;
/**
* #var string
*
* #ORM\Column(name="video1", type="text", length=65535, nullable=true)
*/
private $video1;
/**
* #var string
*
* #ORM\Column(name="video2", type="text", length=65535, nullable=true)
*/
private $video2;
/**
* #var string
*
* #ORM\Column(name="friendly_url", type="string", length=255, nullable=true)
*/
private $friendly_url;
/**
* #var string
*
* #ORM\Column(name="shop_assignment", type="text", length=65535, nullable=true)
*/
private $shop_assignment;
/**
* #var string
*
* #ORM\Column(name="custom_product_type", type="string", length=255, nullable=true)
*/
private $custom_product_type;
/**
* Set model
*
* #param string $model
* #return Product
*/
public function setModel($model)
{
$this->model = $model;
return $this;
}
/**
* Get model
*
* #return string
*/
public function getModel()
{
return $this->model;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set productType
*
* #param \Mp\ShopBundle\Entity\ProductType $productType
* #return Product
*/
public function setProductType(\Mp\ShopBundle\Entity\ProductType $productType = null)
{
$this->productType = $productType;
return $this;
}
/**
* Get productType
*
* #return \Mp\ShopBundle\Entity\ProductType
*/
public function getProductType()
{
return $this->productType;
}
/**
* Get translations
*
* #return \Mp\ShopBundle\Entity\ProductLanguageData
*/
public function getTranslations()
{
return $this->translations;
}
/**
* Set translations
*
* #param \Doctrine\ORM\PersistentCollection $translations
* #return Product
*/
public function setTranslations(\Doctrine\ORM\PersistentCollection $translations)
{
$this->translations = new ArrayCollection();
foreach ($translations as $s) {
$this->addTranslation($s);
}
return $this;
}
/**
* Add translation
*
* #param \Mp\ShopBundle\Entity\ProductLanguageData $translation
*/
public function addTranslation(\Mp\ShopBundle\Entity\ProductLanguageData $translation)
{
$translation->setProduct($this);
$this->translations[] = $translation;
}
/**
* Remove translation
*
* #param \Mp\ShopBundle\Entity\ProductLanguageData $translation
*/
public function removeTranslation(\Mp\ShopBundle\Entity\ProductLanguageData $translation)
{
foreach ($this->translations as $k => $s) {
if ($s->getId() == $translation->getId()) {
unset($this->translations[$k]);
}
}
}
/**
* Get string value
*
* #return string
*/
public function __toString()
{
return ($this->admin_title == "") ? "Product" : $this->admin_title;
}
/**
* Constructor
*/
public function __construct()
{
//$this->translations = new \Doctrine\Common\Collections\ArrayCollection();
$this->tags = new ArrayCollection();
$this->status = false;
}
/**
* Set admin_title
*
* #param string $adminTitle
* #return Product
*/
public function setAdminTitle($adminTitle)
{
$this->admin_title = $adminTitle;
return $this;
}
/**
* Get admin_title
*
* #return string
*/
public function getAdminTitle()
{
return $this->admin_title;
}
/**
* Add tags
*
* #param \Sonata\ClassificationBundle\Model\TagInterface $tags
*/
public function addTags(TagInterface $tags)
{
$this->tags[] = $tags;
}
/**
* Get tags
*
* #return array $tags
*/
public function getTags()
{
return $this->tags;
}
/**
* #param $tags
*
* #return mixed
*/
public function setTags($tags)
{
$this->tags = $tags;
}
/**
* Set category
*
* #param \Application\Sonata\ClassificationBundle\Entity\Category $category
* #return Product
*/
public function setCategory(\Application\Sonata\ClassificationBundle\Entity\Category $category = null)
{
$this->category = $category;
return $this;
}
/**
* Get category
*
* #return \Application\Sonata\ClassificationBundle\Entity\Category
*/
public function getCategory()
{
return $this->category;
}
/**
* Add tags
*
* #param \Application\Sonata\ClassificationBundle\Entity\Tag $tags
* #return Product
*/
public function addTag(\Application\Sonata\ClassificationBundle\Entity\Tag $tags)
{
$this->tags[] = $tags;
return $this;
}
/**
* Remove tags
*
* #param \Application\Sonata\ClassificationBundle\Entity\Tag $tags
*/
public function removeTag(\Application\Sonata\ClassificationBundle\Entity\Tag $tags)
{
$this->tags->removeElement($tags);
}
/**
* Set subcategory
*
* #param \Application\Sonata\ClassificationBundle\Entity\Category $subcategory
* #return Product
*/
public function setSubcategory(\Application\Sonata\ClassificationBundle\Entity\Category $subcategory = null)
{
$this->subcategory = $subcategory;
return $this;
}
/**
* Get subcategory
*
* #return \Application\Sonata\ClassificationBundle\Entity\Category
*/
public function getSubcategory()
{
return $this->subcategory;
}
/**
* Set manufacturer
*
* #param \Application\Sonata\ClassificationBundle\Entity\Collection $manufacturer
* #return Product
*/
public function setManufacturer(\Application\Sonata\ClassificationBundle\Entity\Collection $manufacturer = null)
{
$this->manufacturer = $manufacturer;
return $this;
}
/**
* Get manufacturer
*
* #return \Application\Sonata\ClassificationBundle\Entity\Collection
*/
public function getManufacturer()
{
return $this->manufacturer;
}
/**
* Set status
*
* #param boolean $status
* #return Product
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* Get status
*
* #return boolean
*/
public function getStatus()
{
return $this->status;
}
/**
* Set created_at
*
* #param \DateTime $createdAt
* #return Product
*/
public function setCreatedAt($createdAt)
{
$this->created_at = $createdAt;
return $this;
}
/**
* Get created_at
*
* #return \DateTime
*/
public function getCreatedAt()
{
return $this->created_at;
}
/**
* Set updated_at
*
* #param \DateTime $updatedAt
* #return Product
*/
public function setUpdatedAt($updatedAt)
{
$this->updated_at = $updatedAt;
return $this;
}
/**
* Get updated_at
*
* #return \DateTime
*/
public function getUpdatedAt()
{
return $this->updated_at;
}
/**
* Set pc
*
* #param string $pc
* #return Product
*/
public function setPc($pc)
{
$this->pc = $pc;
return $this;
}
/**
* Get pc
*
* #return string
*/
public function getPc()
{
return $this->pc;
}
/**
* Set value
*
* #param string $value
* #return Product
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
/**
* Get value
*
* #return string
*/
public function getValue()
{
return $this->value;
}
/**
* Set discount
*
* #param string $discount
* #return Product
*/
public function setDiscount($discount)
{
$this->discount = $discount;
return $this;
}
/**
* Get discount
*
* #return string
*/
public function getDiscount()
{
return $this->discount;
}
/**
* Set base
*
* #param string $base
* #return Product
*/
public function setBase($base)
{
$this->base = $base;
return $this;
}
/**
* Get base
*
* #return string
*/
public function getBase()
{
return $this->base;
}
/**
* 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 stock
*
* #param string $stock
* #return Product
*/
public function setStock($stock)
{
$this->stock = $stock;
return $this;
}
/**
* Get stock
*
* #return string
*/
public function getStock()
{
return $this->stock;
}
/**
* Set map
*
* #param string $map
* #return Product
*/
public function setMap($map)
{
$this->map = $map;
return $this;
}
/**
* Get map
*
* #return string
*/
public function getMap()
{
return $this->map;
}
/**
* Set feature1
*
* #param string $feature1
* #return Product
*/
public function setFeature1($feature1)
{
$this->feature1 = $feature1;
return $this;
}
/**
* Get feature1
*
* #return string
*/
public function getFeature1()
{
return $this->feature1;
}
/**
* Set feature2
*
* #param string $feature2
* #return Product
*/
public function setFeature2($feature2)
{
$this->feature2 = $feature2;
return $this;
}
/**
* Get feature2
*
* #return string
*/
public function getFeature2()
{
return $this->feature2;
}
/**
* Set feature3
*
* #param string $feature3
* #return Product
*/
public function setFeature3($feature3)
{
$this->feature3 = $feature3;
return $this;
}
/**
* Get feature3
*
* #return string
*/
public function getFeature3()
{
return $this->feature3;
}
/**
* Set feature4
*
* #param string $feature4
* #return Product
*/
public function setFeature4($feature4)
{
$this->feature4 = $feature4;
return $this;
}
/**
* Get feature4
*
* #return string
*/
public function getFeature4()
{
return $this->feature4;
}
/**
* Set feature5
*
* #param string $feature5
* #return Product
*/
public function setFeature5($feature5)
{
$this->feature5 = $feature5;
return $this;
}
/**
* Get feature5
*
* #return string
*/
public function getFeature5()
{
return $this->feature5;
}
/**
* Set feature6
*
* #param string $feature6
* #return Product
*/
public function setFeature6($feature6)
{
$this->feature6 = $feature6;
return $this;
}
/**
* Get feature6
*
* #return string
*/
public function getFeature6()
{
return $this->feature6;
}
/**
* Set feature7
*
* #param string $feature7
* #return Product
*/
public function setFeature7($feature7)
{
$this->feature7 = $feature7;
return $this;
}
/**
* Get feature7
*
* #return string
*/
public function getFeature7()
{
return $this->feature7;
}
/**
* Set feature8
*
* #param string $feature8
* #return Product
*/
public function setFeature8($feature8)
{
$this->feature8 = $feature8;
return $this;
}
/**
* Get feature8
*
* #return string
*/
public function getFeature8()
{
return $this->feature8;
}
/**
* Set published
*
* #param boolean $published
* #return Product
*/
public function setPublished($published)
{
$this->published = $published;
return $this;
}
/**
* Get published
*
* #return boolean
*/
public function getPublished()
{
return $this->published;
}
/**
* Set url_marketing
*
* #param string $urlMarketing
* #return Product
*/
public function setUrlMarketing($urlMarketing)
{
$this->url_marketing = $urlMarketing;
return $this;
}
/**
* Get url_marketing
*
* #return string
*/
public function getUrlMarketing()
{
return $this->url_marketing;
}
/**
* Set cesion_tienda
*
* #param string $cesionTienda
* #return Product
*/
public function setCesionTienda($cesionTienda)
{
$this->cesion_tienda = $cesionTienda;
return $this;
}
/**
* Get cesion_tienda
*
* #return string
*/
public function getCesionTienda()
{
return $this->cesion_tienda;
}
/**
* Set google
*
* #param string $google
* #return Product
*/
public function setGoogle($google)
{
$this->google = $google;
return $this;
}
/**
* Get google
*
* #return string
*/
public function getGoogle()
{
return $this->google;
}
/**
* Set provider_reference
*
* #param string $providerReference
* #return Product
*/
public function setProviderReference($providerReference)
{
$this->provider_reference = $providerReference;
return $this;
}
/**
* Get provider_reference
*
* #return string
*/
public function getProviderReference()
{
return $this->provider_reference;
}
/**
* Set gallery
*
* #param \Application\Sonata\MediaBundle\Entity\Gallery $gallery
* #return Product
*/
public function setGallery(\Application\Sonata\MediaBundle\Entity\Gallery $gallery = null)
{
$this->gallery = $gallery;
return $this;
}
/**
* Get gallery
*
* #return \Application\Sonata\MediaBundle\Entity\Gallery
*/
public function getGallery()
{
return $this->gallery;
}
/**
* Set vat
*
* #param string $vat
* #return Product
*/
public function setVat($vat)
{
$this->vat = $vat;
return $this;
}
/**
* Get vat
*
* #return string
*/
public function getVat()
{
return $this->vat;
}
/**
* Set provider
*
* #param \Application\Sonata\UserBundle\Entity\User $provider
* #return Product
*/
public function setProvider(\Application\Sonata\UserBundle\Entity\User $provider = null)
{
$this->provider = $provider;
return $this;
}
/**
* Get provider
*
* #return \Application\Sonata\UserBundle\Entity\User
*/
public function getProvider()
{
return $this->provider;
}
/**
* Set video1
*
* #param string $video1
* #return Product
*/
public function setVideo1($video1)
{
$this->video1 = $video1;
return $this;
}
/**
* Get custom_product_type
*
* #return string
*/
public function getCustomProductType()
{
return $this->custom_product_type;
}
}
So for some reason it is passing the wrong class? How can this be fixed?
Yes, you are passing the wrong class in your twig template.
In this part of code:
{% for item in product %}
<td>${{getTotalPrice(item)}}.00</td>
{% endfor %}
You are passing the item parameter which is the instance of Product class.
You should rewrite your Twig extension to accept Product instanses:
public function getTotalPrice($items)
{
$total = 0;
foreach($items as $item){
$total += $item->getPrice();
}
return $total;
}
And then pass the whole array, not only one Product:
<td>${{getTotalPrice(product)}}.00</td>
Hope this helps!
If you want pass a reference of you Product object (entity), you have to inform it to your method:
use Mp\ShopBundle\Entity\Product; - src/AppBundle/Twig/AppExtension.php
And then change your Items to Product object:
...
public function getTotalPrice(Product $items) {
....
I have an entity called DoerTrip
namespace Application\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Doer Trip
*
* #ORM\Table(name="doer_trip")
* #ORM\Entity
*/
class DoerTrip extends AbstractEntity
{
const STATUS_PUBLISHED = 1;
const STATUS_UNPUBLISHED = 0;
/**
* #var integer
*
* #ORM\Column(name="`id`", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* #var \Application\Entity\Doer
*
* #ORM\ManyToOne(targetEntity="Doer")
* #ORM\JoinColumn(name="`doer_id`", referencedColumnName="id")
*/
protected $doer; // inversedBy="trips"
/**
* #var \Application\Entity\Trip
*
* #ORM\ManyToOne(targetEntity="Trip")
* #ORM\JoinColumn(name="`trip_id`", referencedColumnName="id")
*/
protected $trip; //inversedBy="doers"
/**
* #var bool
*
* #ORM\Column(name="`published`", type="boolean")
*/
protected $published;
/**
* #var string
*
* #ORM\Column(name="`comment`", type="text")
*/
protected $comment;
/**
* #var integer
*
* #ORM\Column(name="`target_sum`", type="integer")
*/
protected $targetSum;
public function __construct()
{
$this->published = false;
}
/**
* #param string $comment
* #return $this
*/
public function setComment($comment)
{
$this->comment = $comment;
return $this;
}
/**
* #return string
*/
public function getComment()
{
return $this->comment;
}
/**
* #param \Application\Entity\Doer $doer
* #return $this
*/
public function setDoer(Doer $doer)
{
$this->doer = $doer;
return $this;
}
/**
* #return \Application\Entity\Doer
*/
public function getDoer()
{
return $this->doer;
}
/**
* #param int $id
* #return $this
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* #param boolean $published
* #return $this
*/
public function setPublished($published)
{
$this->published = $published;
return $this;
}
/**
* #return boolean
*/
public function getPublished()
{
return $this->published;
}
/**
* #param \Application\Entity\Trip $trip
* #return $this
*/
public function setTrip(Trip $trip)
{
$this->trip = $trip;
return $this;
}
/**
* #return \Application\Entity\Trip
*/
public function getTrip()
{
return $this->trip;
}
/**
* #param int $targetSum
* #return $this
*/
public function setTargetSum($targetSum)
{
$this->targetSum = $targetSum;
return $this;
}
/**
* #return int
*/
public function getTargetSum()
{
return (null !== $this->targetSum) ? $this->targetSum : $this->getTrip()->getTargetAmount();
}
}
here Trip Entity:
namespace Application\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Zend\Validator\IsInstanceOf;
/**
* Trip
*
* #ORM\Table(name="trip")
* #ORM\Entity
*/
class Trip extends AbstractEntity
{
const STATUS_ACTIVE = 'active';
const STATUS_INACTIVE = 'inactive';
const STATUS_BANNED = 'banned';
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
protected $name;
/**
* #var Collection
*
* #ORM\ManyToMany(targetEntity="Media", cascade={"remove"}, orphanRemoval=true)
* #ORM\JoinTable(name="trip_media",
* joinColumns={#ORM\JoinColumn(name="trip_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="file_id", referencedColumnName="id", unique=true)}
* )
*/
protected $media;
/**
* #var \Application\Entity\Media
*
* #ORM\OneToOne(targetEntity="Media", mappedBy="trip", cascade={"persist", "remove"})
* #ORM\JoinColumn(name="main_media_id", referencedColumnName="id")
*/
protected $mainMedia;
/**
* #var string
*
* #ORM\Column(name="api_key", type="string", length=255)
*/
protected $apiKey;
/**
* #var string
*
* #ORM\Column(name="country", type="string", length=255, nullable=true)
*/
protected $country;
/**
* #var \DateTime
*
* #ORM\Column(name="departure_date", type="date", nullable=true)
*/
protected $departureDate;
/**
* #var \DateTime
*
* #ORM\Column(name="due_date", type="date", nullable=true)
*/
protected $dueDate;
/**
* #var \DateTime
*
* #ORM\Column(name="return_date", type="date", nullable=true)
*/
protected $returnDate;
/**
* #var string
*
* #ORM\Column(name="description", type="text", nullable=true)
*/
protected $description;
/**
* #var string
*
* #ORM\Column(name="target_amount", type="integer")
*/
protected $targetAmount;
/**
* #var Collection
*
* #ORM\OneToMany(targetEntity="DoerTrip", mappedBy="trip", cascade={"persist","remove"}, orphanRemoval=true)
*/
protected $doers;
/**
* #var Organization
*
* #ORM\ManyToOne(targetEntity="Organization", inversedBy="trips")
* #ORM\JoinColumn(name="organization_id", referencedColumnName="id")
*/
protected $organization;
/**
* #var Cause
*
* #ORM\OneToOne(targetEntity="Cause", inversedBy="trips")
* #ORM\JoinColumn(name="cause_id", referencedColumnName="id", onDelete="SET NULL")
*/
protected $cause;
/**
* #var integer
*
* #ORM\Column(name="status", type="string" ,columnDefinition="ENUM('active', 'inactive', 'banned')")
*/
protected $status;
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* #var Transaction
*
* #ORM\OneToMany(targetEntity="Transaction", mappedBy="trip", cascade={"remove"}, orphanRemoval=true)
*/
protected $transactions;
/**
* #param Organization $organization
* #return $this
*/
public function setOrganization(Organization $organization)
{
$this->organization = $organization;
return $this;
}
/**
* #return Organization
*/
public function getOrganization()
{
return $this->organization;
}
public function __construct()
{
$this->doers = new ArrayCollection();
$this->media = new ArrayCollection();
$this->status = self::STATUS_ACTIVE;
$this->transactions = new ArrayCollection();
$this->targetAmount = 0;
$this->description = '';
}
/**
* #param string $apiKey
* #return $this
*/
public function setApiKey($apiKey)
{
$this->apiKey = $apiKey;
return $this;
}
/**
* #return string
*/
public function getApiKey()
{
return $this->apiKey;
}
/**
* #param string $country
* #return $this
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* #return string
*/
public function getCountry()
{
return $this->country;
}
/**
* #param string $description
* #return $this
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* #param \DateTime $dueDate
* #return $this
*/
public function setDueDate(\DateTime $dueDate)
{
$this->dueDate = $dueDate;
return $this;
}
/**
* #return \DateTime
*/
public function getDueDate()
{
return $this->dueDate;
}
/**
* #param int $id
* #return $this
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* #param \DateTime $departureDate
* #return $this
*/
public function setDepartureDate(\DateTime $departureDate)
{
$this->departureDate = $departureDate;
return $this;
}
/**
* #return \DateTime
*/
public function getDepartureDate()
{
return $this->departureDate;
}
/**
* #param string $targetAmount
* #return $this
*/
public function setTargetAmount($targetAmount)
{
$this->targetAmount = $targetAmount;
return $this;
}
/**
* #return string
*/
public function getTargetAmount()
{
return $this->targetAmount;
}
/**
* #param string $name
* #return $this
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* #param int $status
* #return $this
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* #return int
*/
public function getStatus()
{
return $this->status;
}
/**
* #param \Application\Entity\Cause $cause
* #return $this
*/
public function setCause($cause)
{
$this->cause = $cause;
return $this;
}
/**
* #return \Application\Entity\Cause
*/
public function getCause()
{
return $this->cause;
}
/**
* #param \Doctrine\Common\Collections\Collection $media
* #return $this
*/
public function setMedia($media)
{
$this->media = $media;
return $this;
}
/**
* #return \Doctrine\Common\Collections\Collection
*/
public function getMedia()
{
return $this->media;
}
/**
* #param \Application\Entity\DoerTrip $doer
* #return $this
*/
public function addDoer(DoerTrip $doer)
{
$this->doers->add($doer);
$doer->setTrip($this);
return $this;
}
/**
* #param Collection $doers
* #return $this
*/
public function setDoers(Collection $doers)
{
$this->doers = $doers;
return $this;
}
/**
* #return Collection
*/
public function getDoers()
{
return $this->doers;
}
/**
* #param \Application\Entity\DoerTrip $doer
* #return $this
*/
public function removeDoer(DoerTrip $doer)
{
$this->doers->removeElement($doer);
return $this;
}
/**
* #param \Doctrine\Common\Collections\Collection $transactions
* #return $this
*/
public function setTransactions($transactions)
{
$this->transactions = $transactions;
return $this;
}
/**
* #return \Doctrine\Common\Collections\Collection
*/
public function getTransactions()
{
return $this->transactions;
}
/**
* #param array $data
* #return $this
*/
public function populate(array $data)
{
if (!empty($data['departureDate']) && !$data['departureDate'] instanceof \DateTime) {
$data['departureDate'] = new \DateTime($data['departureDate']);
}
if (!empty($data['dueDate']) && !$data['dueDate'] instanceof \DateTime) {
$data['dueDate'] = new \DateTime($data['dueDate']);
}
if (!empty($data['returnDate']) && !$data['returnDate'] instanceof \DateTime) {
$data['returnDate'] = new \DateTime($data['returnDate']);
}
parent::populate($data);
return $this;
}
/**
* #param \DateTime $returnDate
* #return $this
*/
public function setReturnDate(\DateTime $returnDate)
{
$this->returnDate = $returnDate;
return $this;
}
/**
* #return \DateTime
*/
public function getReturnDate()
{
return $this->returnDate;
}
/**
* #param \Application\Entity\Media $mainMedia
* #return $this
*/
public function setMainMedia($mainMedia)
{
$this->mainMedia = $mainMedia;
return $this;
}
/**
* #return \Application\Entity\Media
*/
public function getMainMedia()
{
return $this->mainMedia;
}
/**
* #param Media $media
* #return bool
*/
public function hasMedia(Media $media)
{
return $this->getMedia()->contains($media);
}
/**
* #param \Application\Entity\Media $media
* #return $this
*/
public function addMedia(Media $media)
{
$this->media->add($media);
return $this;
}
/**
* #param \Application\Entity\Media $media
* #return $this
*/
public function removeMedia(Media $media)
{
$this->media->removeElement($media);
return $this;
}
}
Here is Doer Entity
namespace Application\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Zend\Validator\IsInstanceOf;
/**
* Trip
*
* #ORM\Table(name="trip")
* #ORM\Entity
*/
class Trip extends AbstractEntity
{
const STATUS_ACTIVE = 'active';
const STATUS_INACTIVE = 'inactive';
const STATUS_BANNED = 'banned';
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
protected $name;
/**
* #var Collection
*
* #ORM\ManyToMany(targetEntity="Media", cascade={"remove"}, orphanRemoval=true)
* #ORM\JoinTable(name="trip_media",
* joinColumns={#ORM\JoinColumn(name="trip_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="file_id", referencedColumnName="id", unique=true)}
* )
*/
protected $media;
/**
* #var \Application\Entity\Media
*
* #ORM\OneToOne(targetEntity="Media", mappedBy="trip", cascade={"persist", "remove"})
* #ORM\JoinColumn(name="main_media_id", referencedColumnName="id")
*/
protected $mainMedia;
/**
* #var string
*
* #ORM\Column(name="api_key", type="string", length=255)
*/
protected $apiKey;
/**
* #var string
*
* #ORM\Column(name="country", type="string", length=255, nullable=true)
*/
protected $country;
/**
* #var \DateTime
*
* #ORM\Column(name="departure_date", type="date", nullable=true)
*/
protected $departureDate;
/**
* #var \DateTime
*
* #ORM\Column(name="due_date", type="date", nullable=true)
*/
protected $dueDate;
/**
* #var \DateTime
*
* #ORM\Column(name="return_date", type="date", nullable=true)
*/
protected $returnDate;
/**
* #var string
*
* #ORM\Column(name="description", type="text", nullable=true)
*/
protected $description;
/**
* #var string
*
* #ORM\Column(name="target_amount", type="integer")
*/
protected $targetAmount;
/**
* #var Collection
*
* #ORM\OneToMany(targetEntity="DoerTrip", mappedBy="trip", cascade={"persist","remove"}, orphanRemoval=true)
*/
protected $doers;
/**
* #var Organization
*
* #ORM\ManyToOne(targetEntity="Organization", inversedBy="trips")
* #ORM\JoinColumn(name="organization_id", referencedColumnName="id")
*/
protected $organization;
/**
* #var Cause
*
* #ORM\OneToOne(targetEntity="Cause", inversedBy="trips")
* #ORM\JoinColumn(name="cause_id", referencedColumnName="id", onDelete="SET NULL")
*/
protected $cause;
/**
* #var integer
*
* #ORM\Column(name="status", type="string" ,columnDefinition="ENUM('active', 'inactive', 'banned')")
*/
protected $status;
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* #var Transaction
*
* #ORM\OneToMany(targetEntity="Transaction", mappedBy="trip", cascade={"remove"}, orphanRemoval=true)
*/
protected $transactions;
/**
* #param Organization $organization
* #return $this
*/
public function setOrganization(Organization $organization)
{
$this->organization = $organization;
return $this;
}
/**
* #return Organization
*/
public function getOrganization()
{
return $this->organization;
}
public function __construct()
{
$this->doers = new ArrayCollection();
$this->media = new ArrayCollection();
$this->status = self::STATUS_ACTIVE;
$this->transactions = new ArrayCollection();
$this->targetAmount = 0;
$this->description = '';
}
/**
* #param string $apiKey
* #return $this
*/
public function setApiKey($apiKey)
{
$this->apiKey = $apiKey;
return $this;
}
/**
* #return string
*/
public function getApiKey()
{
return $this->apiKey;
}
/**
* #param string $country
* #return $this
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* #return string
*/
public function getCountry()
{
return $this->country;
}
/**
* #param string $description
* #return $this
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* #param \DateTime $dueDate
* #return $this
*/
public function setDueDate(\DateTime $dueDate)
{
$this->dueDate = $dueDate;
return $this;
}
/**
* #return \DateTime
*/
public function getDueDate()
{
return $this->dueDate;
}
/**
* #param int $id
* #return $this
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* #param \DateTime $departureDate
* #return $this
*/
public function setDepartureDate(\DateTime $departureDate)
{
$this->departureDate = $departureDate;
return $this;
}
/**
* #return \DateTime
*/
public function getDepartureDate()
{
return $this->departureDate;
}
/**
* #param string $targetAmount
* #return $this
*/
public function setTargetAmount($targetAmount)
{
$this->targetAmount = $targetAmount;
return $this;
}
/**
* #return string
*/
public function getTargetAmount()
{
return $this->targetAmount;
}
/**
* #param string $name
* #return $this
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* #param int $status
* #return $this
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* #return int
*/
public function getStatus()
{
return $this->status;
}
/**
* #param \Application\Entity\Cause $cause
* #return $this
*/
public function setCause($cause)
{
$this->cause = $cause;
return $this;
}
/**
* #return \Application\Entity\Cause
*/
public function getCause()
{
return $this->cause;
}
/**
* #param \Doctrine\Common\Collections\Collection $media
* #return $this
*/
public function setMedia($media)
{
$this->media = $media;
return $this;
}
/**
* #return \Doctrine\Common\Collections\Collection
*/
public function getMedia()
{
return $this->media;
}
/**
* #param \Application\Entity\DoerTrip $doer
* #return $this
*/
public function addDoer(DoerTrip $doer)
{
$this->doers->add($doer);
$doer->setTrip($this);
return $this;
}
/**
* #param Collection $doers
* #return $this
*/
public function setDoers(Collection $doers)
{
$this->doers = $doers;
return $this;
}
/**
* #return Collection
*/
public function getDoers()
{
return $this->doers;
}
/**
* #param \Application\Entity\DoerTrip $doer
* #return $this
*/
public function removeDoer(DoerTrip $doer)
{
$this->doers->removeElement($doer);
return $this;
}
/**
* #param \Doctrine\Common\Collections\Collection $transactions
* #return $this
*/
public function setTransactions($transactions)
{
$this->transactions = $transactions;
return $this;
}
/**
* #return \Doctrine\Common\Collections\Collection
*/
public function getTransactions()
{
return $this->transactions;
}
/**
* #param array $data
* #return $this
*/
public function populate(array $data)
{
if (!empty($data['departureDate']) && !$data['departureDate'] instanceof \DateTime) {
$data['departureDate'] = new \DateTime($data['departureDate']);
}
if (!empty($data['dueDate']) && !$data['dueDate'] instanceof \DateTime) {
$data['dueDate'] = new \DateTime($data['dueDate']);
}
if (!empty($data['returnDate']) && !$data['returnDate'] instanceof \DateTime) {
$data['returnDate'] = new \DateTime($data['returnDate']);
}
parent::populate($data);
return $this;
}
/**
* #param \DateTime $returnDate
* #return $this
*/
public function setReturnDate(\DateTime $returnDate)
{
$this->returnDate = $returnDate;
return $this;
}
/**
* #return \DateTime
*/
public function getReturnDate()
{
return $this->returnDate;
}
/**
* #param \Application\Entity\Media $mainMedia
* #return $this
*/
public function setMainMedia($mainMedia)
{
$this->mainMedia = $mainMedia;
return $this;
}
/**
* #return \Application\Entity\Media
*/
public function getMainMedia()
{
return $this->mainMedia;
}
/**
* #param Media $media
* #return bool
*/
public function hasMedia(Media $media)
{
return $this->getMedia()->contains($media);
}
/**
* #param \Application\Entity\Media $media
* #return $this
*/
public function addMedia(Media $media)
{
$this->media->add($media);
return $this;
}
/**
* #param \Application\Entity\Media $media
* #return $this
*/
public function removeMedia(Media $media)
{
$this->media->removeElement($media);
return $this;
}
}
I perform this sample of code:
$doerTrip = new DoerTrip();
$doerTrip->setDoer($doer)->setTrip($trip);
$em->persist($doerTrip);
$em->flush();
locally it works (on Windows). But on staging (Ubuntu) new record is not created and I don't get any errors. Update of the entity DoerTrip on staging doesn't work too.
If I perform insert with the help of connection something like this
$stmt = $conn->prepare('INSERT INTO doer_trip (...) VALUES (?,?,?,?,?)');
$stmt->bindParam(1, $param);
...
everything works fine.
When using ORM in SQL Logger I can see
START TRANSACTION;
INSERT INTO doer_trip (...) VALUES (?,?,?,?,?)
COMMIT;
but new record is not created on staging.
locally everything works fine.
I don't know maybe it depends on MySQL configuration.
I have no idea.
Here my doer_trip table
CREATE TABLE `doer_trip` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`doer_id` INT(11) NOT NULL,
`trip_id` INT(11) UNSIGNED NOT NULL,
`published` INT(1) UNSIGNED NOT NULL DEFAULT '0',
`comment` TEXT NULL,
`target_sum` INT(10) UNSIGNED NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `doer_id` (`doer_id`),
INDEX `trip_id` (`trip_id`),
UNIQUE INDEX `doer_iduniq` (`doer_id`, `trip_id`),
CONSTRAINT `FK_doer_trip_trip` FOREIGN KEY (`trip_id`) REFERENCES `trip` (`id`),
CONSTRAINT `FK_doer_trip_doer` FOREIGN KEY (`doer_id`) REFERENCES `doer` (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
AUTO_INCREMENT=41
The problem was in
/**
* #var bool
*
* #ORM\Column(name="`published`", type="boolean")
*/
protected $published;
If I set type to integer like this
/**
* #var integer
*
* #ORM\Column(name="`published`", type="integer")
*/
protected $published;
Everything work fine. But why it works fine on my local environment???