TYPO3 filereference adding two files - typo3

I have TYPO3 7.6.18
this is my code:
$newVideo = new \Istar\Fefiles\Domain\Model\Video();
$videoName = $video['name'];
$videoTmpName = $video['tmp_name'];
$resourceFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
$storage = $resourceFactory->getDefaultStorage();
$folder = $storage->getFolder("user_upload/");
$movedFile = $storage->addFile($videoTmpName, $folder, $videoName);
$newFileReference = $this->objectManager$this->objectManager->get('TYPO3\\CMS\\Extbase\\Domain\\Model\\FileReference');
$newFileReference->setFile($movedFile);
$newVideo->setVideo($newFileReference);
$this->videoRepository->add($newVideo);
$persistenceManager = $this->objectManager->get("TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager");
$persistenceManager->persistAll();
The problem is it added two files to field video file reference. It's very sudenly! And second file is't the same, it's diferent files. I sure, I send one file. Where may be the problem ?
I have model photo, and there is field image
'image' => [
'exclude' => 0,
'label' => 'LLL:EXT:fefiles/Resources/Private/Language/locallang_db.xlf:image',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('image', [
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference'
],
'maxitems' => 1,
], $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'])
],
Anf I see that when I create photo from BE, and upload image - this add second image, which was uploaded on site early. This is very strange! What happens ?
My video model:
<?php
namespace Istar\Fefiles\Domain\Model;
class Video extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
/**
* #var bool
*/
public $allow_for_user = true;
/**
* Title
*
* #var string
* #validate NotEmpty
*/
protected $title = '';
/**
* Description
*
* #var string
*/
protected $description = '';
/**
* rulesDescription
*
* #var string
*/
protected $rulesDescription = '';
/**
* User
*
* #var \Fhk\Feusersplus\Domain\Model\User>
*/
protected $user;
/**
* Videocategory
*
* #var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Istar\Fefiles\Domain\Model\Videocategory>
*/
protected $videocategory;
/**
* Videocomment
*
* #var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Istar\Fefiles\Domain\Model\Videocomment>
* #cascade remove
*/
protected $comment;
/**
* Allow
*
* #var int
*/
protected $allow = 0;
/**
* fskcheck
*
* #var int
*/
protected $fskcheck = 0;
/**
* private
*
* #var int
*/
protected $private = 0;
/**
* Video
* #validate NotEmpty
* #var \TYPO3\CMS\Extbase\Domain\Model\FileReference
* #cascade remove
*/
protected $video;
/**
* preview
*
* #var \TYPO3\CMS\Extbase\Domain\Model\FileReference
* #cascade remove
*/
protected $preview = null;
/**
* blurred
*
* #var \TYPO3\CMS\Extbase\Domain\Model\FileReference
* #cascade remove
*/
protected $blurred = null;
/**
* Crdate
*
* #var int
* #validate NotEmpty
*/
protected $crdate = 0;
/**
* Returns the title
*
* #return string $title
*/
public function getTitle()
{
return $this->title;
}
/**
* Sets the title
*
* #param string $title
* #return void
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Returns the description
*
* #return string $description
*/
public function getDescription()
{
return $this->description;
}
/**
* Sets the description
*
* #param string $description
* #return void
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* Returns the rulesDescription
*
* #return string $rulesDescription
*/
public function getRulesDescription()
{
return $this->rulesDescription;
}
/**
* Sets the rulesDescription
*
* #param string $rulesDescription
* #return void
*/
public function setRulesDescription($rulesDescription)
{
$this->rulesDescription = $rulesDescription;
}
/**
* Returns the video
*
* #return \TYPO3\CMS\Extbase\Domain\Model\FileReference $video
*/
public function getVideo()
{
return $this->video;
}
/**
* Returns the videocategory
*
* #return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Istar\Fefiles\Domain\Model\Videocategory> $videocategory
*/
public function getVideocategory()
{
return $this->videocategory;
}
/**
* Sets the videocategory
*
* #return void
*/
public function setVideocategory($videocategory)
{
$this->videocategory = $videocategory;
}
/**
* Returns the comment
*
* #return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Istar\Fefiles\Domain\Model\Videocomment> $comment
*/
public function getComment()
{
return $this->comment;
}
/**
* Sets the comment
*
* #return void
*/
public function setComment($comment)
{
$this->comment = $comment;
}
/**
* Adds a comments to the video
*
* #param \Istar\Fefiles\Domain\Model\Videocomment $comment
* #return void
* #api
*/
public function addComment(\Istar\Fefiles\Domain\Model\Videocomment $comment)
{
$this->comment->attach($comment);
}
/**
* Removes a comment from the video
*
* #param \Istar\Fefiles\Domain\Model\Videocomment $comment
* #return void
* #api
*/
public function removeComment(\Istar\Fefiles\Domain\Model\Videocomment $comment)
{
$this->comment->detach($comment);
}
/**
* Returns the user
*
* #return \Fhk\Feusersplus\Domain\Model\User> $user
*/
public function getUser()
{
return $this->user;
}
/**
* Sets the user
*
* #return void
*/
public function setUser($user)
{
$this->user = $user;
}
/**
* Returns the allow
*
* #return int
*/
public function getAllow()
{
return $this->allow;
}
/**
* Sets the video
*
* #param \TYPO3\CMS\Extbase\Domain\Model\FileReference $video
* #return void
*/
public function setVideo($video)
{
$this->video = $video;
}
/**
* Returns the preview
*
* #return \TYPO3\CMS\Extbase\Domain\Model\FileReference $preview
*/
public function getPreview()
{
return $this->preview;
}
/**
* Sets the preview
*
* #param \TYPO3\CMS\Extbase\Domain\Model\FileReference $preview
*
* #return void
*/
public function setPreview($preview)
{
$this->preview = $preview;
}
/**
* Returns the blurred
*
* #return \TYPO3\CMS\Extbase\Domain\Model\FileReference $blurred
*/
public function getBlurred()
{
return $this->blurred;
}
/**
* Sets the blurred
*
* #param \TYPO3\CMS\Extbase\Domain\Model\FileReference $blurred
*
* #return void
*/
public function setBlurred($blurred)
{
$this->blurred = $blurred;
}
/**
* Returns the fskcheck
*
* #return int
*/
public function getFskcheck()
{
return $this->fskcheck;
}
/**
* Sets the fskcheck
*
* #return void
*/
public function setFskcheck($fskcheck)
{
$this->fskcheck = $fskcheck;
}
/**
* Returns the Private
*
* #return int
*/
public function getPrivate()
{
return $this->private;
}
/**
* Sets the private
*
* #return void
*/
public function setPrivate($private)
{
$this->private = $private;
}
/**
* Returns the crdate
* #return int $crdate
*/
public function getCrdate()
{
return $this->crdate;
}
/**
* Sets the crdate
*
* #param int $crdate
* #return void
*/
public function setCrdate($crdate)
{
$this->crdate = $crdate;
}
}

Have a look at the sys_file_reference table before and after you create a new record in the backend. Is there a new record added? And after saving an existing record you don't get the random image/video added?

Solution:
'foreign_match_fields' => array(
'fieldname' => 'image',
'tablenames' => 'tx_fefiles_domain_model_photo',
'table_local' => 'sys_file_reference',
),

Related

FOSUserBundle - Embed formtype

help me please ! I would like to embed form of the FOSUserBundle form in another form builder of an entity. When I do it there is no validation test in user entity. i m novice in symfony.
exemple :
->add('user', RegistrationType::class)
class FolderType extends AbstractType
{
/**
* {#inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('user', RegistrationType::class)
->add('firstname', TextType::class)
->add('lastname', TextType::class)
->add('dateBirth', BirthdayType::class)
->add('nationality', CountryType::class,
array(
'preferred_choices' => array(
'France', 'FR')
))
->add('phone', NumberType::class)
->add('save', SubmitType::class);
}
add function in controller :
public function addAction(Request $request, School $schoolId)
{
$em = $this->getDoctrine()->getManager();
$school = $em->getRepository('SchoolBundle:School')->findOneById($schoolId);
$candidat = new candidat();
//School Parameter
$candidat->setSchool($schoolId);
$form = $this->createForm('CandidacyBundle\Form\Onepage\FolderType', $candidat, array('schoolId' => $schoolId));
if($request->isMethod('POST') && $form->handleRequest($request)->isValid())
{
//exit(\Doctrine\Common\Util\Debug::dump($candidat));
$em->persist($candidat);
$em->flush();
$this->get('session')->getFlashBag()->add('notice','Yours new candidacy is added !');
return $this->redirectToRoute('candidacy_home');
}
return $this->render('CandidacyBundle:Folder_B:folder.html.twig', array(
'school' => $school,
'new_folder' => $form->createView()
));
}
REGISTRATION TYPE
namespace UserBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
class RegistrationType extends AbstractType{
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder;
}
public function getParent()
{
return 'FOS\UserBundle\Form\Type\RegistrationFormType';
}
public function getBlockPrefix()
{
return 'app_user_registration';
}
}
CANDIDAT ENTITY
namespace CandidacyBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\mapping\Annotation as Gedmo;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* Candidat
*
* #ORM\Table()
* #ORM\Entity
*/
class Candidat
{
//x - x - x - x - x - x - x - x - x - x - x - x - x - x - OBJ
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\OneToOne(targetEntity="UserBundle\Entity\User", cascade={"persist"})
* #ORM\JoinColumn(nullable=false)
* #Assert\Valid
*/
private $user;
/**
* #ORM\ManyToOne(targetEntity="SchoolBundle\Entity\School")
* #ORM\JoinColumn(name="id_school", referencedColumnName="id", nullable=true)
*/
private $school;
/**
* #var boolean
*
* #ORM\Column(name="state", type="boolean")
*/
private $state = true;
/**
* #var boolean
*
* #ORM\Column(name="state_blacklist", type="boolean")
*/
private $stateBlacklist = false;
/**
* #var \DateTime
*
* #ORM\Column(name="date_entry", type="datetime")
*/
private $dateEntry;
/**
* #var string
* #Assert\NotBlank()
* #Assert\Length(min=3)
* #ORM\Column(name="name", type="string", length=255, nullable=true)
*/
private $firstname;
/**
* #var string
* #Assert\NotBlank(message="Vous devez indiquer votre nom")
* #Assert\Length(min=3)
* #Assert\Regex(
* pattern="/\d/",
* match=false,
* message="Uniquement des lettres"
* )
* #ORM\Column(name="lastname", type="string", length=255, nullable=true)
*/
private $lastname;
/**
* #var \date
* #ORM\Column(name="date_birth", type="date", nullable=true)
*/
private $dateBirth;
/**
* #var string
*
* #ORM\Column(name="nationality", type="string", length=255, nullable=true)
*/
private $nationality;
/**
* #var integer
*
* #ORM\Column(name="phone", type="integer", nullable=true)
*/
private $phone;
/**
* #var string
*
* #ORM\Column(name="adress_street", type="string", length=255, nullable=true)
*/
private $adress_street;
/**
* #var string
*
* #ORM\Column(name="adress_city", type="string", length=255, nullable=true)
*/
private $adress_city;
/**
* #var string
*
* #ORM\Column(name="adress_region", type="string", length=255, nullable=true)
*/
private $adress_region;
/**
* #var string
*
* #ORM\Column(name="adress_country", type="string", length=255, nullable=true)
*/
private $adress_country;
/**
* #var integer
*
* #ORM\Column(name="adress_zip", type="smallint", nullable=true)
*/
private $adress_zip;
/**
* #ORM\ManyToOne(targetEntity="SchoolBundle\Entity\Level", cascade={"persist"})
* #ORM\JoinColumn(name="study_current_level", referencedColumnName="id", nullable=true)
*/
private $studyCurrentLevel;
/**
* #var string
*
* #ORM\Column(name="study_current_graduate_name", type="string", length=50)
*/
private $studyCurrentGraduateName;
/**
* #ORM\ManyToOne(targetEntity="SchoolBundle\Entity\Graduate", cascade={"persist"})
* #ORM\JoinColumn(name="study_current_graduate", referencedColumnName="id", nullable=true )
*/
private $studyCurrentGraduate;
/**
* #ORM\ManyToOne(targetEntity="SchoolBundle\Entity\Graduate")
* #ORM\JoinColumn(name="study_widh_graduate", referencedColumnName="id", nullable=true )
*/
private $studyWishGraduate;
/**
* #ORM\ManyToOne(targetEntity="SchoolBundle\Entity\Sector")
* #ORM\JoinColumn(nullable=true)
*/
private $studyWishSector;
/**
* #ORM\ManyToMany(targetEntity="SchoolBundle\Entity\Speciality")
* #ORM\JoinTable(name="candidat_Speciality")
*/
private $studyWishSpecialities;
/**
* #ORM\ManyToOne(targetEntity="SchoolBundle\Entity\Section")
* #ORM\JoinColumn(nullable=true)
*/
private $studyWishSection;
/**
* #ORM\ManyToMany(targetEntity="SchoolBundle\Entity\Diploma", cascade={"persist"})
* #ORM\JoinTable(name="candidat_diploma")
*/
private $studyWishDiplomas;
/**
* #ORM\ManyToOne(targetEntity="SchoolBundle\Entity\Rhythm", cascade={"persist"})
* #ORM\JoinColumn(name="study_wish_rhythm", referencedColumnName="id", nullable=true)
*/
private $studyWishRhythm;
/**
* #var boolean
*
* #ORM\Column(name="study_wish_place_study", type="boolean", nullable=true)
*/
private $studyWishPlaceStudy;
/**
* #ORM\OneToOne(targetEntity="CandidacyBundle\Entity\Attachment", cascade={"all"})
* #ORM\JoinColumn(name="file_picture", nullable=true)
*/
private $picture;
/**
* #ORM\OneToOne(targetEntity="CandidacyBundle\Entity\Attachment", cascade={"all"})
* #ORM\JoinColumn(name="file_cv", nullable=true)
*/
private $cv;
/**
* #ORM\ManyToMany(targetEntity="CandidacyBundle\Entity\Attachment",cascade={"persist"})
* #ORM\JoinTable(name="candidat_attachment")
*/
private $attachments;
//x - x - x - x - x - x - x - x - x - x - x - x - x - x - CONSTRUCT
public function __construct()
{
$this->dateEntry = new \DateTime();
$this->attachments = new ArrayCollection();
}
//x - x - x - x - x - x - x - x - x - x - x - x - x - x - GET/SET
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set state
*
* #param boolean $state
*
* #return Candidat
*/
public function setState($state)
{
$this->state = $state;
return $this;
}
/**
* Get state
*
* #return boolean
*/
public function getState()
{
return $this->state;
}
/**
* Set stateBlacklist
*
* #param boolean $stateBlacklist
*
* #return Candidat
*/
public function setStateBlacklist($stateBlacklist)
{
$this->stateBlacklist = $stateBlacklist;
return $this;
}
/**
* Get stateBlacklist
*
* #return boolean
*/
public function getStateBlacklist()
{
return $this->stateBlacklist;
}
/**
* Set dateEntry
*
* #param \DateTime $dateEntry
*
* #return Candidat
*/
public function setDateEntry($dateEntry)
{
$this->dateEntry = $dateEntry;
return $this;
}
/**
* Get dateEntry
*
* #return \DateTime
*/
public function getDateEntry()
{
return $this->dateEntry;
}
/**
* Set firstname
*
* #param string $firstname
*
* #return Candidat
*/
public function setFirstname($firstname)
{
$this->firstname = $firstname;
return $this;
}
/**
* Get firstname
*
* #return string
*/
public function getFirstname()
{
return $this->firstname;
}
/**
* Set lastname
*
* #param string $lastname
*
* #return Candidat
*/
public function setLastname($lastname)
{
$this->lastname = $lastname;
return $this;
}
/**
* Get lastname
*
* #return string
*/
public function getLastname()
{
return $this->lastname;
}
/**
* Set dateBirth
*
* #param \DateTime $dateBirth
*
* #return Candidat
*/
public function setDateBirth($dateBirth)
{
$this->dateBirth = $dateBirth;
return $this;
}
/**
* Get dateBirth
*
* #return \DateTime
*/
public function getDateBirth()
{
return $this->dateBirth;
}
/**
* Set email
*
* #param string $email
*
* #return Candidat
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* #return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set nationality
*
* #param string $nationality
*
* #return Candidat
*/
public function setNationality($nationality)
{
$this->nationality = $nationality;
return $this;
}
/**
* Get nationality
*
* #return string
*/
public function getNationality()
{
return $this->nationality;
}
/**
* Set phone
*
* #param integer $phone
*
* #return Candidat
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* Get phone
*
* #return integer
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set adressStreet
*
* #param string $adressStreet
*
* #return Candidat
*/
public function setAdressStreet($adressStreet)
{
$this->adress_street = $adressStreet;
return $this;
}
/**
* Get adressStreet
*
* #return string
*/
public function getAdressStreet()
{
return $this->adress_street;
}
/**
* Set adressCity
*
* #param string $adressCity
*
* #return Candidat
*/
public function setAdressCity($adressCity)
{
$this->adress_city = $adressCity;
return $this;
}
/**
* Get adressCity
*
* #return string
*/
public function getAdressCity()
{
return $this->adress_city;
}
/**
* Set adressRegion
*
* #param string $adressRegion
*
* #return Candidat
*/
public function setAdressRegion($adressRegion)
{
$this->adress_region = $adressRegion;
return $this;
}
/**
* Get adressRegion
*
* #return string
*/
public function getAdressRegion()
{
return $this->adress_region;
}
/**
* Set adressCountry
*
* #param string $adressCountry
*
* #return Candidat
*/
public function setAdressCountry($adressCountry)
{
$this->adress_country = $adressCountry;
return $this;
}
/**
* Get adressCountry
*
* #return string
*/
public function getAdressCountry()
{
return $this->adress_country;
}
/**
* Set adressZip
*
* #param integer $adressZip
*
* #return Candidat
*/
public function setAdressZip($adressZip)
{
$this->adress_zip = $adressZip;
return $this;
}
/**
* Get adressZip
*
* #return integer
*/
public function getAdressZip()
{
return $this->adress_zip;
}
/**
* Set studyCurrentLevel
*
* #param string $studyCurrentLevel
*
* #return Candidat
*/
public function setStudyCurrentLevel($studyCurrentLevel)
{
$this->studyCurrentLevel = $studyCurrentLevel;
return $this;
}
/**
* Get studyCurrentLevel
*
* #return string
*/
public function getStudyCurrentLevel()
{
return $this->studyCurrentLevel;
}
/**
* Set studyCurrentGraduateName
*
* #param string $studyCurrentGraduateName
*
* #return Candidat
*/
public function setStudyCurrentGraduateName($studyCurrentGraduateName)
{
$this->studyCurrentGraduateName = $studyCurrentGraduateName;
return $this;
}
/**
* Get studyCurrentGraduateName
*
* #return string
*/
public function getStudyCurrentGraduateName()
{
return $this->studyCurrentGraduateName;
}
/**
* Set studyCurrentGraduate
*
* #param string $studyCurrentGraduate
*
* #return Candidat
*/
public function setStudyCurrentGraduate($studyCurrentGraduate)
{
$this->studyCurrentGraduate = $studyCurrentGraduate;
return $this;
}
/**
* Get studyCurrentGraduate
*
* #return string
*/
public function getStudyCurrentGraduate()
{
return $this->studyCurrentGraduate;
}
/**
* Set studyWishGraduate
*
* #param string $studyWishGraduate
*
* #return Candidat
*/
public function setStudyWishGraduate($studyWishGraduate)
{
$this->studyWishGraduate = $studyWishGraduate;
return $this;
}
/**
* Get studyWishGraduate
*
* #return string
*/
public function getStudyWishGraduate()
{
return $this->studyWishGraduate;
}
/**
* Set studyWishSector
*
* #param string $studyWishSector
*
* #return Candidat
*/
public function setStudyWishSector($studyWishSector)
{
$this->studyWishSector = $studyWishSector;
return $this;
}
/**
* Get studyWishSector
*
* #return string
*/
public function getStudyWishSector()
{
return $this->studyWishSector;
}
/**
* Set studyWishRhythm
*
* #param string $studyWishRhythm
*
* #return Candidat
*/
public function setStudyWishRhythm($studyWishRhythm)
{
$this->studyWishRhythm = $studyWishRhythm;
return $this;
}
/**
* Get studyWishRhythm
*
* #return string
*/
public function getStudyWishRhythm()
{
return $this->studyWishRhythm;
}
/**
* Set studyWishPlaceStudy
*
* #param string $studyWishPlaceStudy
*
* #return Candidat
*/
public function setStudyWishPlaceStudy($studyWishPlaceStudy)
{
$this->studyWishPlaceStudy = $studyWishPlaceStudy;
return $this;
}
/**
* Get studyWishPlaceStudy
*
* #return string
*/
public function getStudyWishPlaceStudy()
{
return $this->studyWishPlaceStudy;
}
/**
* Set user
*
* #param guid $user
*
* #return \UserBundle\Entity\User $user
*/
public function setUser($user)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* #return \UserBundle\Entity\User
*/
public function getUser()
{
return $this->user;
}
/**
* Set studyWishSpecialities
*
* #param \SchoolBundle\Entity\Speciality $studyWishSpecialities
*
* #return Candidat
*/
public function setStudyWishSpecialities($studyWishSpecialities)
{
$this->studyWishSpecialities = $studyWishSpecialities;
return $this;
}
/**
* Get studyWishSpecialities
*
* #return \SchoolBundle\Entity\Speciality
*/
public function getStudyWishSpecialities()
{
return $this->studyWishSpecialities;
}
public function setPicture(Attachment $picture = null)
{
$this->picture = $picture;
}
public function getPicture()
{
return $this->picture;
}
public function setCv(Attachment $cv = null)
{
$this->cv = $cv;
}
public function getCv()
{
return $this->cv;
}
/**
* Add attachment
*
* #param \CandidacyBundle\Entity\Attachment $attachment
*
* #return Candidat
*/
public function addAttachment(\CandidacyBundle\Entity\Attachment $attachment)
{
$this->attachments[] = $attachment;
return $this;
}
/**
* Remove attachment
*
* #param \CandidacyBundle\Entity\Attachment $attachment
*/
public function removeAttachment(\CandidacyBundle\Entity\Attachment $attachment)
{
$this->attachments->removeElement($attachment);
}
/**
* Get attachments
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getAttachments()
{
return $this->attachments;
}
/**
* Set school
*
* #param \SchoolBundle\Entity\School $school
*
* #return Candidat
*/
public function setSchool(\SchoolBundle\Entity\School $school = null)
{
$this->school = $school;
return $this;
}
/**
* Get school
*
* #return \SchoolBundle\Entity\School
*/
public function getSchool()
{
return $this->school;
}
/**
* Add studyWishSpeciality
*
* #param \SchoolBundle\Entity\Speciality $studyWishSpeciality
*
* #return Candidat
*/
public function addStudyWishSpeciality(\SchoolBundle\Entity\Speciality $studyWishSpeciality)
{
$this->studyWishSpecialities[] = $studyWishSpeciality;
return $this;
}
/**
* Remove studyWishSpeciality
*
* #param \SchoolBundle\Entity\Speciality $studyWishSpeciality
*/
public function removeStudyWishSpeciality(\SchoolBundle\Entity\Speciality $studyWishSpeciality)
{
$this->studyWishSpecialities->removeElement($studyWishSpeciality);
}
/**
* Set studyWishSection
*
* #param \SchoolBundle\Entity\Section $studyWishSection
*
* #return Candidat
*/
public function setStudyWishSection(\SchoolBundle\Entity\Section $studyWishSection = null)
{
$this->studyWishSection = $studyWishSection;
return $this;
}
/**
* Get studyWishSection
*
* #return \SchoolBundle\Entity\Section
*/
public function getStudyWishSection()
{
return $this->studyWishSection;
}
/**
* Add studyWishDiploma
*
* #param \SchoolBundle\Entity\Diploma $studyWishDiploma
*
* #return Candidat
*/
public function addStudyWishDiploma(\SchoolBundle\Entity\Diploma $studyWishDiploma)
{
$this->studyWishDiploma[] = $studyWishDiploma;
return $this;
}
/**
* Remove studyWishDiploma
*
* #param \SchoolBundle\Entity\Diploma $studyWishDiploma
*/
public function removeStudyWishDiploma(\SchoolBundle\Entity\Diploma $studyWishDiploma)
{
$this->studyWishDiploma->removeElement($studyWishDiploma);
}
/**
* Get studyWishDiploma
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getStudyWishDiploma()
{
return $this->studyWishDiploma;
}
/**
* Get studyWishDiplomas
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getStudyWishDiplomas()
{
return $this->studyWishDiplomas;
}
}

Symfony / Doctrine - Id already exist

I have a problem. I moved website to another hosting(so I exported DB and imported to new hosting).
But now, when I trying to add new record to database. I have an error stn like ID 1 already exist. But I have almost 500 records in the table.
What can I do to fix it?
Sorry I've should provide more information:
I exported and imported database through phppgadmin I didn't use migrations bundle.
Here is my entity:
class Products
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="serial_number", type="string", length=255, nullable=true)
*/
private $serial;
/**
* #var string
* #Expose
* #ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* #var string
* #Expose
* #ORM\Column(name="url", type="string", length=255)
*/
private $url;
/**
* #var string
* #ORM\Column(name="note", type="text", nullable=true)
*/
private $note;
/**
* #var int
*
* #ORM\Column(name="views", type="bigint", nullable=true)
*/
private $views;
/**
* #ORM\ManyToMany(targetEntity="Models")
* #ORM\JoinTable(name="products_models",
* joinColumns={#ORM\JoinColumn(name="product_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="model_id", referencedColumnName="id")}
* )
*/
private $models;
/**
* #ORM\OneToOne(targetEntity="ProductDetails", cascade={"persist", "remove"})
* #ORM\JoinColumn(name="details_id", referencedColumnName="id")
*/
private $details;
/**
* #var File
* #Expose
* #ORM\OneToMany(targetEntity="ProductImages", mappedBy="product", cascade={"persist", "remove"})
* #ORM\OrderBy({"id" = "ASC"})
*
*/
private $images;
/**
* #var File
*
* #ORM\OneToMany(targetEntity="Cart", mappedBy="productId", cascade={"persist"})
*
*/
private $cart;
/**
* #var string
*
* #ORM\Column(name="price", type="integer", length=255, nullable=true)
*/
private $price;
/**
* #var string
*
* #ORM\Column(name="bought_price", type="integer", length=255, nullable=true)
*/
private $boughtPrice;
/**
* #var string
*
* #ORM\Column(name="old_price", type="integer", length=255, nullable=true)
*/
private $oldPrice;
/**
* #var bool
*
* #ORM\Column(name="is_active", type="boolean", nullable=true)
*/
private $isActive;
/**
* #var bool
*
* #ORM\Column(name="is_accessory", type="boolean", nullable=true)
*/
private $isAccessory;
/**
* #ORM\ManyToOne(targetEntity="AccessoryCategory")
* #ORM\JoinColumn(name="accessory_category_id", referencedColumnName="id")
*/
private $accessoryCategory;
/**
* #var bool
*
* #ORM\Column(name="is_special", type="boolean", nullable=true)
*/
private $isSpecial;
/**
* #var integer
*
* #ORM\Column(name="quantity", type="integer", nullable=true)
*/
private $quantity;
/**
* created Time/Date
*
* #var \DateTime
*
* #ORM\Column(name="created_at", type="datetime", nullable=false)
*/
protected $createdAt;
/**
* updated Time/Date
*
* #var \DateTime
*
* #ORM\Column(name="updated_at", type="datetime", nullable=false)
*/
protected $updatedAt;
/**
* #var boolean
*
* #ORM\Column(name="seller", type="boolean", length=255, nullable=true)
*/
private $seller;
/**
* Set createdAt
*
* #ORM\PrePersist
*/
public function setCreatedAt()
{
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
}
/**
* Get createdAt
*
* #return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set updatedAt
*
* #ORM\PreUpdate
*/
public function setUpdatedAt()
{
$this->updatedAt = new \DateTime();
}
/**
* Get updatedAt
*
* #return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* #param string $title
*
* #return Products
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set url
*
* #param string $url
*
* #return Products
*/
public function setUrl($url)
{
$this->url = $url;
return $this;
}
/**
* Get url
*
* #return string
*/
public function getUrl()
{
return $this->url;
}
/**
* Set note
*
* #param string $note
*
* #return Products
*/
public function setNote($note)
{
$this->note = $note;
return $this;
}
/**
* Get note
*
* #return string
*/
public function getNote()
{
return $this->note;
}
/**
* Set views
*
* #param integer $views
*
* #return Products
*/
public function setViews($views)
{
$this->views = $views;
return $this;
}
/**
* Get views
*
* #return integer
*/
public function getViews()
{
return $this->views;
}
/**
* Set price
*
* #param integer $price
*
* #return Products
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* Get price
*
* #return integer
*/
public function getPrice()
{
return $this->price;
}
/**
* Set boughtPrice
*
* #param integer $boughtPrice
*
* #return Products
*/
public function setBoughtPrice($boughtPrice)
{
$this->boughtPrice = $boughtPrice;
return $this;
}
/**
* Get boughtPrice
*
* #return integer
*/
public function getBoughtPrice()
{
return $this->boughtPrice;
}
/**
* Set isActive
*
* #param boolean $isActive
*
* #return Products
*/
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
/**
* Get isActive
*
* #return boolean
*/
public function getIsActive()
{
return $this->isActive;
}
/**
* Set isAccessory
*
* #param boolean $isAccessory
*
* #return Products
*/
public function setIsAccessory($isAccessory)
{
$this->isAccessory = $isAccessory;
return $this;
}
/**
* Get isAccessory
*
* #return boolean
*/
public function getIsAccessory()
{
return $this->isAccessory;
}
/**
* Set quantity
*
* #param integer $quantity
*
* #return Products
*/
public function setQuantity($quantity)
{
$this->quantity = $quantity;
return $this;
}
/**
* Get quantity
*
* #return integer
*/
public function getQuantity()
{
return $this->quantity;
}
/**
* Set details
*
* #param \Web\AdminBundle\Entity\ProductDetails $details
*
* #return Products
*/
public function setDetails(\Web\AdminBundle\Entity\ProductDetails $details = null)
{
$this->details = $details;
return $this;
}
/**
* Get details
*
* #return \Web\AdminBundle\Entity\ProductDetails
*/
public function getDetails()
{
return $this->details;
}
/**
* Add image
*
* #param \Web\AdminBundle\Entity\ProductImages $image
*
* #return Products
*/
public function addImage(\Web\AdminBundle\Entity\ProductImages $image)
{
$this->images[] = $image;
return $this;
}
/**
* Remove image
*
* #param \Web\AdminBundle\Entity\ProductImages $image
*/
public function removeImage(\Web\AdminBundle\Entity\ProductImages $image)
{
$this->images->removeElement($image);
}
/**
* Get images
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getImages()
{
return $this->images;
}
/**
* Add cart
*
* #param \Web\AdminBundle\Entity\Cart $cart
*
* #return Products
*/
public function addCart(\Web\AdminBundle\Entity\Cart $cart)
{
$this->cart[] = $cart;
return $this;
}
/**
* Remove cart
*
* #param \Web\AdminBundle\Entity\Cart $cart
*/
public function removeCart(\Web\AdminBundle\Entity\Cart $cart)
{
$this->cart->removeElement($cart);
}
/**
* Get cart
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getCart()
{
return $this->cart;
}
/**
* Set isSpecial
*
* #param boolean $isSpecial
*
* #return Products
*/
public function setIsSpecial($isSpecial)
{
$this->isSpecial = $isSpecial;
return $this;
}
/**
* Get isSpecial
*
* #return boolean
*/
public function getIsSpecial()
{
return $this->isSpecial;
}
/**
* Set accessoryCategory
*
* #param \Web\AdminBundle\Entity\AccessoryCategory $accessoryCategory
*
* #return Products
*/
public function setAccessoryCategory(\Web\AdminBundle\Entity\AccessoryCategory $accessoryCategory = null)
{
$this->accessoryCategory = $accessoryCategory;
return $this;
}
/**
* Get accessoryCategory
*
* #return \Web\AdminBundle\Entity\AccessoryCategory
*/
public function getAccessoryCategory()
{
return $this->accessoryCategory;
}
/**
* Set oldPrice
*
* #param integer $oldPrice
*
* #return Products
*/
public function setOldPrice($oldPrice)
{
$this->oldPrice = $oldPrice;
return $this;
}
/**
* Get oldPrice
*
* #return integer
*/
public function getOldPrice()
{
return $this->oldPrice;
}
/**
* Set serial
*
* #param string $serial
*
* #return Products
*/
public function setSerial($serial)
{
$this->serial = $serial;
return $this;
}
/**
* Get serial
*
* #return string
*/
public function getSerial()
{
return $this->serial;
}
/**
* Constructor
*/
public function __construct()
{
$this->models = new \Doctrine\Common\Collections\ArrayCollection();
$this->images = new \Doctrine\Common\Collections\ArrayCollection();
$this->cart = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add model
*
* #param \Web\AdminBundle\Entity\Models $model
*
* #return Products
*/
public function addModel(\Web\AdminBundle\Entity\Models $model)
{
$this->models[] = $model;
return $this;
}
/**
* Remove model
*
* #param \Web\AdminBundle\Entity\Models $model
*/
public function removeModel(\Web\AdminBundle\Entity\Models $model)
{
$this->models->removeElement($model);
}
/**
* Get models
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getModels()
{
return $this->models;
}
/**
* Set seller
*
* #param boolean $seller
*
* #return Products
*/
public function setSeller($seller)
{
$this->seller = $seller;
return $this;
}
/**
* Get seller
*
* #return boolean
*/
public function getSeller()
{
return $this->seller;
}
I'm adding new like this:
$em = $this->getDoctrine()->getManager();
$products = new Products();
$article->setTitle('here is the title');
....
$em->persist($products);
$em->flush();
this should set id to like 488 but it's trying to set it to 1. And I don't know why? Might be some cache? But php bin/console cache:clear doesn't change anything.
Doctrine use sequence with the auto strategy and Postgres.
Maybe sequence values has been lost when export/import db.
Identify the sequence used by your ID and try to execute :
ALTER SEQUENCE sequence_name RESTART WITH your_next_free_id;
hi i have got the same problem when i Import my database the probléme s like they say sequence.
But because i have more than 100 table i can't reset the sequence one by one So i Found this query it create for all your table an sql query to update the sequence by the max Id, you have just to copy the result and execute it
SELECT 'SELECT SETVAL(' ||
quote_literal(quote_ident(PGT.schemaname) || '.' || quote_ident(S.relname)) ||
', COALESCE(MAX(' ||quote_ident(C.attname)|| '), 1) ) FROM ' ||
quote_ident(PGT.schemaname)|| '.'||quote_ident(T.relname)|| ';'
FROM pg_class AS S,
pg_depend AS D,
pg_class AS T,
pg_attribute AS C,
pg_tables AS PGT
WHERE S.relkind = 'S'
AND S.oid = D.objid
AND D.refobjid = T.oid
AND D.refobjid = C.attrelid
AND D.refobjsubid = C.attnum
AND T.relname = PGT.tablename
ORDER BY S.relname;
I think as other have suggested its not the issue with symfony or doctrine , instead its postgresql common issue, you can check a solution here
Make sure you are using same version, I am not sure if this behavior differs from version to version.
You can change the current value of the auto increment manually like this :
ALTER TABLE products AUTO_INCREMENT=501;

How to use Catalog rule "Conditions_serialized" to validate product attribute?

I have define a condition the which product as product attribute "Hot" equal to "yes" on my table "product_label".
How to use \Magento\CatalogRule\Model\Rule\Condition... to validate $product with my condition?
The condition is record as following
a:7:{s:4:"type";s:48:"Magento\CatalogRule\Model\Rule\Condition
\Combine";s:9:"attribute";N;s:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_
processed";N;s:10:"aggregator";s:3:"all";s:10:"conditions";a:1:{i:0;a:5:
{s:4:"type";s:48:"Magento\CatalogRule\Model\Rule\Condition
\Product";s:9:"attribute";s:7:"hkt_hot";s:8:"operator";s:2:"==";s:5:"value";
s:1:"1";s:18:"is_value_processed";b:0;}}}
Thanks
Norman
Without coding you can make this check using the system already in place:
Your "hot" attribute property is_used_for_promo_rules must be set to 1.
Additionally, the function Mage_Catalog_Model_Resource_Eav_Attribute::isAllowedForRuleCondition() sets the following prerequisites:
An attribute must be visible (attribute property is_visible must be equal 1).
The frontend_input property must be one of the following types: ‘text’, ‘multiselect’, ‘textarea’, ‘date’, ‘datetime’, ‘select’, ‘boolean’, ‘price’.
You may find the list of product IDs satisfying the serialized conditions.
Create model Vendor/Module/Model/Rule.php
<?php
namespace Vendor\Module\Model;
class Rule extends \Magento\CatalogRule\Model\Rule
{
/**
* Prefix of model events names
*
* #var string
*/
protected $_eventPrefix = 'catalogrule_rule';
/**
* Parameter name in event
*
* In observe method you can use $observer->getEvent()->getRule() in this case
*
* #var string
*/
protected $_eventObject = 'rule';
/**
* Store matched product Ids
*
* #var array
*/
protected $_productIds;
/**
* Limitation for products collection
*
* #var int|array|null
*/
protected $_productsFilter = null;
/**
* Store current date at "Y-m-d H:i:s" format
*
* #var string
*/
protected $_now;
/**
* Cached data of prices calculated by price rules
*
* #var array
*/
protected static $_priceRulesData = [];
/**
* Catalog rule data
*
* #var \Magento\CatalogRule\Helper\Data
*/
protected $_catalogRuleData;
/**
*
* #var \Magento\Framework\App\Cache\TypeListInterface
*/
protected $_cacheTypesList;
/**
*
* #var array
*/
protected $_relatedCacheTypes;
/**
*
* #var \Magento\Framework\Stdlib\DateTime
*/
protected $dateTime;
/**
*
* #var \Magento\Framework\Model\ResourceModel\Iterator
*/
protected $_resourceIterator;
/**
*
* #var \Magento\Customer\Model\Session
*/
protected $_customerSession;
/**
*
* #var \Magento\CatalogRule\Model\Rule\Condition\CombineFactory
*/
protected $_combineFactory;
/**
*
* #var \Magento\CatalogRule\Model\Rule\Action\CollectionFactory
*/
protected $_actionCollectionFactory;
/**
*
* #var \Magento\Catalog\Model\ProductFactory
*/
protected $_productFactory;
/**
*
* #var \Magento\Store\Model\StoreManagerInterface
*/
protected $_storeManager;
/**
*
* #var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
*/
protected $_productCollectionFactory;
/**
*
* #var \Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor;
*/
protected $_ruleProductProcessor;
/**
*
* #var Data\Condition\Converter
*/
protected $ruleConditionConverter;
/**
* Rule constructor.
*
* #param \Magento\Framework\Model\Context $context
* #param \Magento\Framework\Registry $registry
* #param \Magento\Framework\Data\FormFactory $formFactory
* #param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
* #param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
* #param \Magento\Store\Model\StoreManagerInterface $storeManager
* #param Rule\Condition\CombineFactory $combineFactory
* #param Rule\Action\CollectionFactory $actionCollectionFactory
* #param \Magento\Catalog\Model\ProductFactory $productFactory
* #param \Magento\Framework\Model\ResourceModel\Iterator $resourceIterator
* #param \Magento\Customer\Model\Session $customerSession
* #param \Magento\CatalogRule\Helper\Data $catalogRuleData
* #param \Magento\Framework\App\Cache\TypeListInterface $cacheTypesList
* #param \Magento\Framework\Stdlib\DateTime $dateTime
* #param Indexer\Rule\RuleProductProcessor $ruleProductProcessor
* #param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* #param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
* #param array $relatedCacheTypes
* #param array $data
*
* #SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Data\FormFactory $formFactory, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\CatalogRule\Model\Rule\Condition\CombineFactory $combineFactory, \Magento\CatalogRule\Model\Rule\Action\CollectionFactory $actionCollectionFactory, \Magento\Catalog\Model\ProductFactory $productFactory, \Magento\Framework\Model\ResourceModel\Iterator $resourceIterator, \Magento\Customer\Model\Session $customerSession, \Magento\CatalogRule\Helper\Data $catalogRuleData, \Magento\Framework\App\Cache\TypeListInterface $cacheTypesList, \Magento\Framework\Stdlib\DateTime $dateTime, \Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor $ruleProductProcessor, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $relatedCacheTypes = [], array $data = [])
{
parent::__construct($context, $registry, $formFactory, $localeDate, $productCollectionFactory, $storeManager, $combineFactory, $actionCollectionFactory, $productFactory, $resourceIterator, $customerSession, $catalogRuleData, $cacheTypesList, $dateTime, $ruleProductProcessor, $resource, $resourceCollection, $relatedCacheTypes, $data);
}
/**
* Init resource model and id field
*
* #return void
*/
protected function _construct()
{
parent::_construct();
$this->_init('Magento\CatalogRule\Model\ResourceModel\Rule');
$this->setIdFieldName('rule_id');
}
/**
* Getter for rule conditions collection
*
* #return \Magento\Rule\Model\Condition\Combine
*/
public function getConditionsInstance()
{
return $this->_combineFactory->create();
}
/**
* Getter for rule actions collection
*
* #return \Magento\CatalogRule\Model\Rule\Action\Collection
*/
public function getActionsInstance()
{
return $this->_actionCollectionFactory->create();
}
public function toArray(array $arrAttributes = array())
{
return parent::toArray($arrAttributes);
}
public function getListProductIds()
{
$productCollection = \Magento\Framework\App\ObjectManager::getInstance()->create('\Magento\Catalog\Model\ResourceModel\Product\Collection');
$productFactory = \Magento\Framework\App\ObjectManager::getInstance()->create('\Magento\Catalog\Model\ProductFactory');
$this->_productIds = [];
$this->setCollectedAttributes([]);
$this->getConditions()->collectValidatedAttributes($productCollection);
\Magento\Framework\App\ObjectManager::getInstance()->create('\Magento\Framework\Model\ResourceModel\Iterator')->walk($productCollection->getSelect(), [
[
$this,
'callbackValidateProduct'
]
], [
'attributes' => $this->getCollectedAttributes(),
'product' => $productFactory->create()
]);
return $this->_productIds;
}
/**
* Callback function for product matching
*
* #param array $args
* #return void
*/
public function callbackValidateProduct($args)
{
$product = clone $args['product'];
$product->setData($args['row']);
$websites = $this->_getWebsitesMap();
foreach ($websites as $websiteId => $defaultStoreId) {
$product->setStoreId($defaultStoreId);
if ($this->getConditions()->validate($product)) {
$this->_productIds[] = $product->getId();
}
}
}
/**
* Prepare website map
*
* #return array
*/
protected function _getWebsitesMap()
{
$map = [];
$websites = \Magento\Framework\App\ObjectManager::getInstance()->create('\Magento\Store\Model\StoreManagerInterface')->getWebsites();
foreach ($websites as $website) {
// Continue if website has no store to be able to create catalog rule for website without store
if ($website->getDefaultStore() === null) {
continue;
}
$map[$website->getId()] = $website->getDefaultStore()->getId();
}
return $map;
}
}
Then, wherever you'd like to find the product IDs. Use below code snippet.
...
private $ruleModel;
...
...
private function getRuleModel()
{
if($this->ruleModel === null) {
$this->ruleModel = $this->objectManager->create('Vendor\Module\Model\Rule');
$this->ruleModel->setName('name')
->setDescription('description')
->setWebsiteIds($this->objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getWebsiteId());
}
return $this->ruleModel;
}
...
...
// somewhere in your method
$matchedProductIds = $this->getRuleModel()
->setData('conditions_serialized', $conditions_serialized)->getListProductIds();
...

Fill my form with the data that I pick up from a table - Symfony2

My problem is this : I have an entity that contains user data , such as:
age
name
surname
address
phone
...
My goal is to make a form where using a query can bring all this data and fill my form with the data , so that the user can modify it if you ever change the cell for example, or changing the direction of his house.
The company and I have made the entity​​ and the form, and consulting the table will do. My problem is how to fill the form fields with the data that I get from the table.
My entity (DatosEntity):
<?php
namespace Proyecto\LavocBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Datos
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="Proyecto\LavocBundle\Entity\DatosRepository")
*/
class Datos
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="empresa", type="string", length=50)
*/
private $empresa;
/**
* #var integer
*
* #ORM\Column(name="cuit", type="integer")
*/
private $cuit;
/**
* #var string
*
* #ORM\Column(name="localidad", type="string", length=50)
*/
private $localidad;
/**
* #var string
*
* #ORM\Column(name="calle", type="string", length=40)
*/
private $calle;
/**
* #var integer
*
* #ORM\Column(name="altura", type="integer")
*/
private $altura;
/**
* #var integer
*
* #ORM\Column(name="areaTel", type="integer")
*/
private $areaTel;
/**
* #var integer
*
* #ORM\Column(name="telefono", type="integer")
*/
private $telefono;
/**
* #var integer
*
* #ORM\Column(name="areaCel", type="integer")
*/
private $areaCel;
/**
* #var integer
*
* #ORM\Column(name="celular", type="integer")
*/
private $celular;
/**
* #ORM\OneToOne(targetEntity="User", inversedBy="datos")
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $personales;
/**
* #var string
*
* #ORM\Column(name="email", type="string")
*/
private $email;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set empresa
*
* #param string $empresa
* #return Datos
*/
public function setEmpresa($empresa)
{
$this->empresa = $empresa;
return $this;
}
/**
* Get empresa
*
* #return string
*/
public function getEmpresa()
{
return $this->empresa;
}
/**
* Set cuit
*
* #param integer $cuit
* #return Datos
*/
public function setCuit($cuit)
{
$this->cuit = $cuit;
return $this;
}
/**
* Get cuit
*
* #return integer
*/
public function getCuit()
{
return $this->cuit;
}
/**
* Set localidad
*
* #param string $localidad
* #return Datos
*/
public function setLocalidad($localidad)
{
$this->localidad = $localidad;
return $this;
}
/**
* Get localidad
*
* #return string
*/
public function getLocalidad()
{
return $this->localidad;
}
/**
* Set calle
*
* #param string $calle
* #return Datos
*/
public function setCalle($calle)
{
$this->calle = $calle;
return $this;
}
/**
* Get calle
*
* #return string
*/
public function getCalle()
{
return $this->calle;
}
/**
* Set altura
*
* #param integer $altura
* #return Datos
*/
public function setAltura($altura)
{
$this->altura = $altura;
return $this;
}
/**
* Get altura
*
* #return integer
*/
public function getAltura()
{
return $this->altura;
}
/**
* Set telefono
*
* #param integer $telefono
* #return Datos
*/
public function setTelefono($telefono)
{
$this->telefono = $telefono;
return $this;
}
/**
* Get telefono
*
* #return integer
*/
public function getTelefono()
{
return $this->telefono;
}
/**
* Set area
*
* #param integer $area
* #return Datos
*/
public function setAreaTel($areaTel)
{
$this->areaTel = $areaTel;
return $this;
}
/**
* Get area
*
* #return integer
*/
public function getAreaTel()
{
return $this->areaTel;
}
/**
* Set celular
*
* #param integer $celular
* #return Datos
*/
public function setCelular($celular)
{
$this->celular = $celular;
return $this;
}
/**
* Get celular
*
* #return integer
*/
public function getCelular()
{
return $this->celular;
}
/**
* Set areaCel
*
* #param integer $areaCel
* #return Datos
*/
public function setAreaCel($areaCel)
{
$this->areaCel = $areaCel;
return $this;
}
/**
* Get areaCel
*
* #return integer
*/
public function getAreaCel()
{
return $this->areaCel;
}
/**
* Set email
*
* #param integer $email
* #return Datos
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* #return integer
*/
public function getEmail()
{
return $this->email;
}
/**
* Set personales
*
* #param string $personales
* #return Datos
*/
public function setPersonales($personales)
{
$this->personales = $personales;
return $this;
}
/**
* Get personales
*
* #return string
*/
public function getPersonales()
{
return $this->personales;
}
}
My DatosType:
<?php
namespace Proyecto\LavocBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class DatosType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('empresa');
$builder->add('cuit');
$builder->add('localidad');
$builder->add('calle');
$builder->add('altura');
$builder->add('areaTel');
$builder->add('telefono');
$builder->add('areaCel');
$builder->add('celular');
}
public function getName()
{
return 'datos_form';
}
}
The consultation on the controller but did not know how to do it. Now , do not like taking the data I receive and dump them in the form.
Thank you very much and sorry for the trouble
I think what you want to do can be done by following these steps :
Start by collecting your User data in a variable we will call $user
Then, give this $userto be hydrated by your form, like this :
$form = $this->createForm(new UserType(), $user);
Treat your form like you would normaly do. The values found in the entity should be automaticaly filled in your form.
Hope this helps.
Your action could be something like this:
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('LavocBundle:User')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find User entity.');
}
$editForm = $this->createForm(new UserType(), $entity);
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
);
}

Create and save a value object in CommandController

im trying to create and save a value object in my ImportCommandController.php, but only the entity will be saved.
Let me show some code:
// Create Entity "Fewo"
$fewo = new Fewo();
$fewo->setTitle('MyFewo');
...
// Create Value Object "Period"
$period = new Period();
$period->setTitle('MyTestTitle');
...
$fewo->addPeriod($period);
$this->fewoRepository->add($fewo);
$this->persistenceManager->persistAll();
Now the Fewo is in the database, but the period-table is still empty. I can't find my mistake...
UPDATE:
This is the Period Model:
<?php
namespace TYPO3\Fewo\Domain\Model;
class Period extends \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject {
/**
* Name der Saison
*
* #var \string
*/
protected $name;
/**
* Von
*
* #var \DateTime
*/
protected $begin;
/**
* Bis
*
* #var \DateTime
*/
protected $end;
/**
* rentalcharges
*
* #var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\Fewo\Domain\Model\Rentalcharge>
*/
protected $rentalcharges;
/**
* __construct
*
* #return Period
*/
public function __construct() {
//Do not remove the next line: It would break the functionality
$this->initStorageObjects();
}
/**
* Initializes all ObjectStorage properties.
*
* #return void
*/
protected function initStorageObjects() {
/**
* Do not modify this method!
* It will be rewritten on each save in the extension builder
* You may modify the constructor of this class instead
*/
$this->rentalcharges = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
/**
* Returns the name
*
* #return \string $name
*/
public function getName() {
return $this->name;
}
/**
* Sets the name
*
* #param \string $name
* #return void
*/
public function setName($name) {
$this->name = $name;
}
/**
* Returns the begin
*
* #return \DateTime $begin
*/
public function getBegin() {
return $this->begin;
}
/**
* Sets the begin
*
* #param \DateTime $begin
* #return void
*/
public function setBegin($begin) {
$this->begin = $begin;
}
/**
* Returns the end
*
* #return \DateTime $end
*/
public function getEnd() {
return $this->end;
}
/**
* Sets the end
*
* #param \DateTime $end
* #return void
*/
public function setEnd($end) {
$this->end = $end;
}
/**
* Adds a Rentalcharge
*
* #param \TYPO3\Fewo\Domain\Model\Rentalcharge $rentalcharge
* #return void
*/
public function addRentalcharge(\TYPO3\Fewo\Domain\Model\Rentalcharge $rentalcharge) {
$this->rentalcharges->attach($rentalcharge);
}
/**
* Removes a Rentalcharge
*
* #param \TYPO3\Fewo\Domain\Model\Rentalcharge $rentalchargeToRemove The Rentalcharge to be removed
* #return void
*/
public function removeRentalcharge(\TYPO3\Fewo\Domain\Model\Rentalcharge $rentalchargeToRemove) {
$this->rentalcharges->detach($rentalchargeToRemove);
}
/**
* Returns the rentalcharges
*
* #return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\Fewo\Domain\Model\Rentalcharge> $rentalcharges
*/
public function getRentalcharges() {
return $this->rentalcharges;
}
/**
* Sets the rentalcharges
*
* #param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\Fewo\Domain\Model\Rentalcharge> $rentalcharges
* #return void
*/
public function setRentalcharges(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $rentalcharges) {
$this->rentalcharges = $rentalcharges;
}
}
UPDATE2:
Tried:
class Period extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {...}
and:
$period = $this->objectManager->get('TYPO3\Fewo\Domain\Model\Period');
with no effect :(
Is Period in FeWo of the right type?
It have to be something like this:
* #var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\Fewo\Domain\Model\Fewo>