Symfony Insert Foreign Key Value - symfony

I have 3 tables: EdiTradingPartner, EdiDocType and EdiTradingPartnerTransactions
src\Matrix\MatrixEdiBundle\Entity\EdiTradingPartner
namespace Matrix\MatrixEdiBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* EdiTradingPartner
*
* #ORM\Table(name="edi_trading_partner")
* #ORM\Entity(repositoryClass="Matrix\MatrixEdiBundle\Repository\EdiTradingPartnerRepository")
*/
class EdiTradingPartner
{
/**
* #var string
*
* #ORM\Column(name="edi_interchange_id", type="string", length=30, nullable=false)
*/
private $ediInterchangeId;
/**
* #var string
*
* #ORM\Column(name="tp_name", type="string", length=30, nullable=false)
*/
private $tpName;
/**
* #var string
*
* #ORM\Column(name="tp_location", type="string", length=50, nullable=false)
*/
private $tpLocation;
/**
* #var integer
*
* #ORM\Column(name="edi_trading_partner_id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $ediTradingPartnerId;
/**
* Set ediInterchangeId
*
* #param string $ediInterchangeId
* #return EdiTradingPartner
*/
public function setEdiInterchangeId($ediInterchangeId)
{
$this->ediInterchangeId = $ediInterchangeId;
return $this;
}
/**
* Get ediInterchangeId
*
* #return string
*/
public function getEdiInterchangeId()
{
return $this->ediInterchangeId;
}
/**
* Set tpName
*
* #param string $tpName
* #return EdiTradingPartner
*/
public function setTpName($tpName)
{
$this->tpName = $tpName;
return $this;
}
/**
* Get tpName
*
* #return string
*/
public function getTpName()
{
return $this->tpName;
}
/**
* Set tpLocation
*
* #param string $tpLocation
* #return EdiTradingPartner
*/
public function setTpLocation($tpLocation)
{
$this->tpLocation = $tpLocation;
return $this;
}
/**
* Get tpLocation
*
* #return string
*/
public function getTpLocation()
{
return $this->tpLocation;
}
/**
* Get ediTradingPartnerId
*
* #return integer
*/
public function getEdiTradingPartnerId()
{
return $this->ediTradingPartnerId;
}
}
src\Matrix\MatrixEdiBundle\Entity\EdiDocType
<?php
namespace Matrix\MatrixEdiBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* EdiDocType
*
* #ORM\Table(name="edi_doc_type")
* #ORM\Entity(repositoryClass="Matrix\MatrixEdiBundle\Repository\EdiDocTypeRepository")
*/
class EdiDocType
{
/**
* #var integer
*
* #ORM\Column(name="doc_type", type="integer", nullable=false)
*/
private $docType;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=50, nullable=false)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="description", type="string", length=255, nullable=false)
*/
private $description;
/**
* #var string
*
* #ORM\Column(name="direction", type="string", length=10, nullable=false)
*/
private $direction;
/**
* #var integer
*
* #ORM\Column(name="edi_doc_type_id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $ediDocTypeId;
/**
* Set docType
*
* #param integer $docType
* #return EdiDocType
*/
public function setDocType($docType)
{
$this->docType = $docType;
return $this;
}
/**
* Get docType
*
* #return integer
*/
public function getDocType()
{
return $this->docType;
}
/**
* Set name
*
* #param string $name
* #return EdiDocType
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set description
*
* #param string $description
* #return EdiDocType
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set direction
*
* #param string $direction
* #return EdiDocType
*/
public function setDirection($direction)
{
$this->direction = $direction;
return $this;
}
/**
* Get direction
*
* #return string
*/
public function getDirection()
{
return $this->direction;
}
/**
* Get ediDocTypeId
*
* #return integer
*/
public function getEdiDocTypeId()
{
return $this->ediDocTypeId;
}
}
src\Matrix\MatrixEdiBundle\Entity\EdiTradingPartnerTransactions
namespace Matrix\MatrixEdiBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* EdiTradingPartnerTransactions
*
* #ORM\Table(name="edi_trading_partner_transactions", indexes={#ORM\Index(name="edi_tp_id", columns={"edi_tp_id", "edi_doc_type_id"}), #ORM\Index(name="edi_transactions_id", columns={"edi_doc_type_id"}), #ORM\Index(name="IDX_F2BE50F7B9C737A1", columns={"edi_tp_id"})})
* #ORM\Entity(repositoryClass="Matrix\MatrixEdiBundle\Repository\EdiTradingPartnerTransactionsRepository")
*/
class EdiTradingPartnerTransactions
{
/**
* #var integer
*
* #ORM\Column(name="edi_tp_transactions_id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $ediTpTransactionsId;
/**
* #var \Matrix\MatrixEdiBundle\Entity\EdiDocType
*
* #ORM\ManyToOne(targetEntity="Matrix\MatrixEdiBundle\Entity\EdiDocType")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="edi_doc_type_id", referencedColumnName="edi_doc_type_id")
* })
*/
private $ediDocType;
/**
* #var \Matrix\MatrixEdiBundle\Entity\EdiTradingPartner
*
* #ORM\ManyToOne(targetEntity="Matrix\MatrixEdiBundle\Entity\EdiTradingPartner")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="edi_tp_id", referencedColumnName="edi_trading_partner_id")
* })
*/
private $ediTp;
/**
* Get ediTpTransactionsId
*
* #return integer
*/
public function getEdiTpTransactionsId()
{
return $this->ediTpTransactionsId;
}
/**
* Set ediDocType
*
* #param \Matrix\MatrixEdiBundle\Entity\EdiDocType $ediDocType
* #return EdiTradingPartnerTransactions
*/
public function setEdiDocType(\Matrix\MatrixEdiBundle\Entity\EdiDocType $ediDocType = null)
{
$this->ediDocType = $ediDocType;
return $this;
}
/**
* Get ediDocType
*
* #return \Matrix\MatrixEdiBundle\Entity\EdiDocType
*/
public function getEdiDocType()
{
return $this->ediDocType;
}
/**
* Set ediTp
*
* #param \Matrix\MatrixEdiBundle\Entity\EdiTradingPartner $ediTp
* #return EdiTradingPartnerTransactions
*/
public function setEdiTp(\Matrix\MatrixEdiBundle\Entity\EdiTradingPartner $ediTp = null)
{
$this->ediTp = $ediTp;
return $this;
}
/**
* Get ediTp
*
* #return \Matrix\MatrixEdiBundle\Entity\EdiTradingPartner
*/
public function getEdiTp()
{
return $this->ediTp;
}
}
I want to insert into EdiTradingPartnerTransactions table yet I really don't know what to do since I've been receiving this error:
Catchable fatal error: Argument 1 passed to
Matrix\MatrixEdiBundle\Entity\EdiTradingPartnerTransactions::setEdiTp()
must be an instance of
Matrix\MatrixEdiBundle\Entity\EdiTradingPartner, string given, called
in
C:\xampp\htdocs\Editracker\src\Matrix\MatrixEdiBundle\Controller\MatrixController.php
on line 474 and defined in
C:\xampp\htdocs\Editracker\src\Matrix\MatrixEdiBundle\Entity\EdiTradingPartnerTransactions.php
on line 85
Here's my function in the controller side:
public function deleteTpTransAction($tpId, $docType, $direction, $tpName) {
$em = $this->getDoctrine()->getManager();
$docTypeId = $em->getRepository('MatrixEdiBundle:EdiDocType')->getId($docType, $direction);
if ($docTypeId != null) {
$result = $em->getRepository('MatrixEdiBundle:EdiTradingPartnerTransactions')->getTpTrans($tpId, $docType, $direction);
if ($result == null) {
$transaction = new EdiTradingPartnerTransactions();
$transaction->setEdiTp($tpId);
$transaction->setEdiDocType($docTypeId);
$em->persist($transaction);
} else {
foreach ($result as $key) {
$id = $key->getEdiTpTransactionsId();
$transaction = $em->getRepository('MatrixEdiBundle:EdiTradingPartnerTransactions')->find($id);
$em->remove($transaction);
}
}
$em->flush();
}
return $this->redirect($this->generateUrl('matrix_edi_tpTrans'));
}
Any help would really be appreciated. Thanks in advanced!

The error here is pretty clear: Doctrine handle, at least for relationships, only objects of the "related" (let's call that way) entity.
When you do
$transaction->setEdiTp($tpId);
$transaction->setEdiDocType($docTypeId);
you're trying to insert ID(s) of related objects. This is an error: although your db expects an integer (foreign key), Doctrine is an abstaction "pillow" between your code and db; it choose to work with objects and not with ids(you can see it pretty clearly into entity classes files)
Solution here is pretty simple:
Fetch from db the entity for setEdiTp and setEdiDocType
Pass them to the functions
In PHP (Symfony):
$ediTp = $em
->getRepository('MatrixEdiBundle:EdiTp')
->findOneById($tpId);
$ediDocType = $em
->getRepository('MatrixEdiBundle:EdiDocType')
->findOneById($docTypeId);
then
$transaction->setEdiTp($ediTp);
$transaction->setEdiDocType($ediDocType);

Your error is because setEdiTp need an instance of EdiTradingPartner.
Your error say string given.
Because $tpId is string.
Verify
Change
$transaction->setEdiTp($tpId);
To
// $transaction->setEdiTp($tpId);
var_dump($tpId);
Normally, $tpId return a string, not a object.
So when you call deleteTpTransAction, $tpId must be an instance of setEdiTp
Changement :
$editp = $em->getRepository('MatrixEdiBundle:EdiTradingPartner')->find($tpId);
and change
$transaction->setEdiTp($tpId);
by
$transaction->setEdiTp($editTp);

Related

How to access entity variable in controller function?

I have a variable private $groupId; in entity. And there is a controller function public function settingsListAction(Request $request)
I want to access that groupId in controller function. How it can be achieved?
Edit
Controller function is
/**
* Get all settings content list
* #Route("settings", name="settings_list")
*/
public function settingsListAction(Request $request)
{
// Cannot edit at all.
//Fetch Current Financial Year target data to display that on "Road to paradise tab"
$entity = new J1Setting();
//do smthing
$groupIdValue = $entity->getGroup();
$settingsGroup = $this->getDoctrine()->getRepository('AppBundle:J1SettingGroup')->findAll();
$settingsList = $this->getDoctrine()->getRepository('AppBundle:J1Setting')->findBy(array('groupId' => groupIdValue));
return $this->render('default/settingsList.html.twig', array('settingsGroup' => $settingsGroup, 'settingsList' => $settingsList));
}
And entity is:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use AppBundle\Component\Annotation\J1Entity;
use Doctrine\Common\Collections\ArrayCollection;
/**
* J1Setting
*
* #ORM\Table(name="j1_settings", indexes={#ORM\Index(name="IDX_SName", columns={"name"})})
* #ORM\Entity(repositoryClass="AppBundle\Repository\J1SettingRepository")
* #J1Entity(auditClass="AppBundle\Component\Audit\J1AuditSetting")
*/
class J1Setting
{
/**
* #var integer
*
* #ORM\Column(name="setting_id", type="integer")
*
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $settingid;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=100, nullable=true)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="value", type="string", length=250, nullable=true)
*/
private $value;
/**
* #var string
*
* #ORM\Column(name="description", type="string", length=255)
*/
private $description;
/**
* #var integer
*
* #ORM\Column(name="group_id", type="integer")
* #ORM\Id
*/
private $groupId;
/**
* #var J1SettingGroup
*
* #ORM\ManyToOne(targetEntity="J1SettingGroup", inversedBy="settings")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="group_id", referencedColumnName="id")
* })
*/
private $group;
/**
* #var string
*
* #ORM\Column(name="setting_type", type="string", length=100)
*/
private $settingType;
/**
* Get settingid
*
* #return integer
*/
public function getSettingId()
{
return $this->settingid;
}
/**
* Set name
*
* #param string $name
* #return J1Setting
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set value
*
* #param string $value
* #return J1Setting
*/
public function setValue($value)
{
$this->value = serialize($value);
return $this;
}
/**
* Get value
*
* #return string
*/
public function getValue()
{
return unserialize($this->value);
}
/**
* Return name replacing underscores with spaces
*
* #return mixed
*/
public function getFriendlyName(){
return str_replace('_', ' ', $this->getName());
}
/**
* Set description
*
* #param string $description
* #return J1Setting
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set groupId
*
* #param integer $groupId
* #return J1Setting
*/
public function setGroupId($groupId)
{
$this->groupId = $groupId;
return $this;
}
/**
* Get groupId
*
* #return integer
*/
public function getGroupId()
{
return $this->groupId;
}
/**
* Set settingType
*
* #param string $settingType
* #return J1Setting
*/
public function setSettingType($settingType)
{
$this->settingType = $settingType;
return $this;
}
/**
* Get settingType
*
* #return string
*/
public function getSettingType()
{
return $this->settingType;
}
/**
* Set group
*
* #param $group
* #return J1Setting
*/
public function setGroup($group = null)
{
$this->group = $group;
return $this;
}
/**
* Get group
*
* #return integer
*/
public function getGroup()
{
return $this->group;
}
}
you need to create a getter in your entity
public function getGroupId(){
return $this->groupId;
}
public function setGroupId($groupId){
$this->groupId = $groupId;
}
and in your controller:
$entity = new J1Setting();
$entity->setGroupId(123);
$groupIdValue = $entity->getGroupId();
var_dump($goupIdValue) //outputs 123
When using Doctrine, you shouldn't put foreign keys into an entity.
This means, groupId should not be part of your J1Setting entity. If you want to access the id of the associated group, then you have to use $entity->getGroup()->getId(). Obviously, this only works, if the entity actually has a group!

count an attribute in an entity

I have an entity "user" that has OneToMany relation with the entity "vehicule". I'm trying to count the number of vehicules for each user. This is my function
$emm = $this->getDoctrine();
$directions = $emm->getRepository('OCUserBundle:User')->findAll();
foreach($directions as $direction) {
$direction->getVehicule()->count();
}
return $this->render('DemandevehBundle:Demande:affiche.html.twig', array('demandes' => $demandes
, ));
but how could I put it in the return so that i could use it in my affiche.html.twig. because I want to show foreach user the number of vehicules he have . Thanks a lot
This is my entity Vehicule
<?php
namespace Car\PfeBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use OC\UserBundle\Entity\User;
/**
* Vehicule
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="Car\PfeBundle\Entity\VehiculeRepository")
*/
class Vehicule
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
*/
private $id;
/**
* #var integer
*
* #ORM\Column(name="carte_grise", type="integer", unique=true)
*/
private $carteGrise;
/**
* #var string
*
* #ORM\Column(name="modele", type="string", length=255)
*/
private $modele;
/**
* #var string
*
* #ORM\Column(name="type", type="string", length=255)
*/
private $type;
/**
* #var string
*
* #ORM\Column(name="categorie", type="string", length=255)
*/
private $categorie;
/**
* #var integer
*
* #ORM\Column(name="puissance", type="integer")
*
*/
private $puissance;
/**
* #var integer
*
* #ORM\Column(name="nb_place", type="integer")
*/
private $nbPlace;
/**
* #var integer
*
* #ORM\Column(name="kilometrage", type="integer")
*/
private $kilometrage;
/**
* #var string
*
* #ORM\Column(name="marque", type="string", length=255)
*/
private $marque;
/**
* #var string
*
* #ORM\Column(name="carburant", type="string", length=255)
*/
private $carburant;
/**
* #var string
*
* #ORM\Column(name="transmission", type="string", length=255)
*/
private $transmission;
/**
* #ORM\ManyToOne(targetEntity="OC\UserBundle\Entity\User", inversedBy="vehicule")
* #ORM\JoinColumn(name="User_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected $direction;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set Id
*
* #param integer $carteGrise
* #return Vehicule
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* Set carteGrise
*
* #param integer $carteGrise
* #return Vehicule
*/
public function setCarteGrise($carteGrise)
{
$this->carteGrise = $carteGrise;
return $this;
}
/**
* Get carteGrise
*
* #return integer
*/
public function getCarteGrise()
{
return $this->carteGrise;
}
/**
* Set modele
*
* #param string $modele
* #return Vehicule
*/
public function setModele($modele)
{
$this->modele = $modele;
return $this;
}
/**
* Get modele
*
* #return string
*/
public function getModele()
{
return $this->modele;
}
/**
* Set categorie
*
* #param string $categorie
* #return Vehicule
*/
public function setCategorie($categorie)
{
$this->categorie = $categorie;
return $this;
}
/**
* Get categorie
*
* #return string
*/
public function getCategorie()
{
return $this->categorie;
}
/**
* Set puissance
*
* #param integer $puissance
* #return Vehicule
*/
public function setPuissance($puissance)
{
$this->puissance = $puissance;
return $this;
}
/**
* Get puissance
*
* #return integer
*/
public function getPuissance()
{
return $this->puissance;
}
/**
* Set nbPlace
*
* #param integer $nbPlace
* #return Vehicule
*/
public function setNbPlace($nbPlace)
{
$this->nbPlace = $nbPlace;
return $this;
}
/**
* Get nbPlace
*
* #return integer
*/
public function getNbPlace()
{
return $this->nbPlace;
}
/**
* Set kilometrage
*
* #param integer $kilometrage
* #return Vehicule
*/
public function setKilometrage($kilometrage)
{
$this->kilometrage = $kilometrage;
return $this;
}
/**
* Get kilometrage
*
* #return integer
*/
public function getKilometrage()
{
return $this->kilometrage;
}
/**
* Set marque
*
* #param string $marque
* #return Vehicule
*/
public function setMarque($marque)
{
$this->marque = $marque;
return $this;
}
/**
* Get marque
*
* #return string
*/
public function getMarque()
{
return $this->marque;
}
/**
* Set carburant
*
* #param string $carburant
* #return Vehicule
*/
public function setCarburant($carburant)
{
$this->carburant = $carburant;
return $this;
}
/**
* Get carburant
*
* #return string
*/
public function getCarburant()
{
return $this->carburant;
}
/**
* Set transmission
*
* #param string $transmission
* #return Vehicule
*/
public function setTransmission($transmission)
{
$this->transmission = $transmission;
return $this;
}
/**
* Get transmission
*
* #return string
*/
public function getTransmission()
{
return $this->transmission;
}
public function __toString()
{
return (string)$this->id;
}
/**
* Set type
*
* #param string $type
* #return Vehicule
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Get type
*
* #return string
*/
public function getType()
{
return $this->type;
}
/**
* Set direction
*
* #param \OC\UserBundle\Entity\User $direction
* #return Vehicule
*/
public function setDirection(\OC\UserBundle\Entity\User $direction = null)
{
$this->direction = $direction;
return $this;
}
/**
* Get direction
*
* #return \OC\UserBundle\Entity\User
*/
public function getDirection()
{
return $this->direction;
}
}
and this is my entity User
<?php
namespace OC\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Car\PfeBundle\Entity\Vehicule;
/**
* User
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="OC\UserBundle\Entity\UserRepository")
*/
class User implements UserInterface
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="username", type="string", length=255, unique=true)
*/
private $username;
/**
* #var string
*
* #ORM\Column(name="password", type="string", length=255)
*/
private $password;
/**
* #var string
*
* #ORM\Column(name="nomDirec", type="string", length=255, unique=true)
*/
private $nomDirec;
/**
* #var string
*
* #ORM\Column(name="directeur", type="string", length=255)
*/
private $directeur;
/**
* #var string
*
* #ORM\Column(name="adresse", type="string", length=255)
*/
private $adresse;
/**
* #var string
*
* #ORM\Column(name="email", type="string", length=255)
*/
private $email;
/**
* #var string
*
* #ORM\Column(name="fax", type="integer")
*/
private $fax;
/**
* #var string
*
* #ORM\Column(name="tel", type="integer")
*/
private $tel;
/**
* #ORM\Column(name="salt", type="string", length=255)
*/
private $salt;
/**
* #ORM\Column(name="roles", type="array")
*/
private $roles = array();
/**
* #ORM\OneToMany(targetEntity="Car\PfeBundle\Entity\Vehicule", mappedBy="direction", cascade={"remove", "persist"})
*/
protected $vehicule;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set username
*
* #param string $username
* #return User
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Get username
*
* #return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set password
*
* #param string $password
* #return User
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* #return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set roles
*
* #param array $roles
* #return User
*/
public function setRoles($roles)
{
$this->roles = $roles;
return $this;
}
/**
* Get roles
*
* #return array
*/
public function getRoles()
{
return $this->roles;
}
public function eraseCredentials()
{
}
/**
* Set nomDirec
*
* #param string $nomDirec
* #return User
*/
public function setNomDirec($nomDirec)
{
$this->nomDirec = $nomDirec;
return $this;
}
/**
* Get nomDirec
*
* #return string
*/
public function getNomDirec()
{
return $this->nomDirec;
}
/**
* Set directeur
*
* #param string $directeur
* #return User
*/
public function setDirecteur($directeur)
{
$this->directeur = $directeur;
return $this;
}
/**
* Get directeur
*
* #return string
*/
public function getDirecteur()
{
return $this->directeur;
}
/**
* Set adresse
*
* #param string $adresse
* #return User
*/
public function setAdresse($adresse)
{
$this->adresse = $adresse;
return $this;
}
/**
* Get adresse
*
* #return string
*/
public function getAdresse()
{
return $this->adresse;
}
/**
* Set email
*
* #param string $email
* #return User
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* #return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set fax
*
* #param \integer $fax
* #return User
*/
public function setFax($fax)
{
$this->fax = $fax;
return $this;
}
/**
* Get fax
*
* #return \integer
*/
public function getFax()
{
return $this->fax;
}
/**
* Set tel
*
* #param integer $tel
* #return User
*/
public function setTel($tel)
{
$this->tel = $tel;
return $this;
}
/**
* Get tel
*
* #return integer
*/
public function getTel()
{
return $this->tel;
}
/**
* Set salt
*
* #param string $salt
* #return User
*/
public function setSalt($salt)
{
$this->salt = $salt;
return $this;
}
/**
* Get salt
*
* #return string
*/
public function getSalt()
{
return $this->salt;
}
public function __toString()
{
return strval( $this->getId() );
}
/**
* Constructor
*/
public function __construct()
{
$this->vehicule = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add vehicule
*
* #param \Car\PfeBundle\Entity\Vehicule $vehicule
* #return User
*/
public function addVehicule(\Car\PfeBundle\Entity\Vehicule $vehicule)
{
$this->vehicule[] = $vehicule;
return $this;
}
/**
* Remove vehicule
*
* #param \Car\PfeBundle\Entity\Vehicule $vehicule
*/
public function removeVehicule(\Car\PfeBundle\Entity\Vehicule $vehicule)
{
$this->vehicule->removeElement($vehicule);
}
/**
* Get vehicule
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getVehicule()
{
return $this->vehicule;
}
}
The correct way to do this in a OOP way , is to define a method that returns the number of vehicules foreach user, so you could to this:
define a getNumberOfVehicules function in your User Class 'Entity'
public function getNumberOfVehicules()
{
return $this->vehicule->count();
}
then in your twig template you just simply call that function , i.e:
{% for user in users %}
<p>{{user.username}} {{user.getNumberOfVehicules()}}</p>
{% endfor %}
to get the desired result, I would do something like this ( haven't tested the query, but it should pretty much work )
$em = $this->getDoctrine();
$userRepository = $em->getRepository('OCUserBundle:User');
$qb = $userRepository->createQueryBuilder('user')
->leftJoin('user.vehicule','vehicule')
->addSelect('COUNT(vehicule.id) AS vehicule_count')
->groupBy('user.id')
->getQuery();
$result = $qb->getResult();
Pass the result to the view
return $this->render('DemandevehBundle:Demande:affiche.html.twig',
array('demandes' => $result ));
In the view you can iterate over the results.
$qb = $this->getEntityManager()->createQueryBuilder();
return $qb->select('u.username as name, count(v.id) as count')
->from('OCUserBundle:User', 'u')
->leftJoin('u.vehicule', 'v')
->groupBy('u.id')
->getQuery()
->getResult();
Here we get an array as result with each user plus no of corresponding vehicles.Just pass result to twig and then foreach name and count.All the best.

Semantical Error in symfony2 while fetching the data

I am trying to write a web service to fetch the category list and all the business under that category in an nested array fashion.
I am getting an Semantical Error saying :
{
code: 500
message: "[Semantical Error] line 0, col 14 near 'StreetBumbApiBundle:Buss_owner': Error: Class 'StreetBumb\ApiBundle\Entity\Buss_owner' is not defined."
}
I already defined the entity in the controller, i dont know why it is showing this error.
This is how my controller's function looks like:
public function getCategoryAction(){
$em = $this->getDoctrine()->getEntityManager();
$pro = $em->getRepository('StreetBumbApiBundle:Category')
->getBusinessByCategory();
//return $pro;
$i = 0;
foreach($pro as $p)
{
$data['category'][$i]['id'] = $p->getId();
$data['category'][$i]['Name'] = $p->getCatName();
//$result[$i] = $p->getId();
$catId = $p->getId();
$business = $em->createQuery('SELECT b FROM StreetBumbApiBundle:Buss_owner b WHERE b.catId = :catId')->setParameter('catId', $catId);
$result = $business->getResult();
foreach($result as $r)
{
$data['business'][$i]['id'][] = $r->getId();
}
$i++;
}
return $data;
}
Please guide if anyone have idea.. Thanx
UPDATE:
Buss_owner Entity:
<?php
namespace StreetBumb\ApiBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Buss_owner
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="StreetBumb\ApiBundle\Entity\Buss_ownerRepository")
*/
class Buss_owner
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=50)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="email", type="string", length=255)
*/
private $email;
/**
* #var integer
*
* #ORM\Column(name="phno", type="integer")
*/
private $phno;
/**
* #var string
*
* #ORM\Column(name="address", type="string", length=255)
*/
private $address;
/**
* #var string
*
* #ORM\Column(name="password", type="string", length=255)
*/
private $password;
/**
* #var string
*
* #ORM\Column(name="fbId", type="integer")
*/
private $fbId;
/**
* #var string
*
* #ORM\Column(name="uniqueId", type="string", length=255)
*/
private $uniqueId;
/**
* #var integer
*
* #ORM\Column(name="catId", type="integer")
* #ORM\ManyToMany(targetEntity="Category", mappedBy="Buss_owner")
*/
private $catId;
public function __construct() {
$this->catId = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* #param string $name
* #return Buss_owner
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set email
*
* #param string $email
* #return Buss_owner
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* #return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set phno
*
* #param integer $phno
* #return Buss_owner
*/
public function setPhno($phno)
{
$this->phno = $phno;
return $this;
}
/**
* Get phno
*
* #return integer
*/
public function getPhno()
{
return $this->phno;
}
/**
* Set address
*
* #param string $address
* #return Buss_owner
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* #return string
*/
public function getAddress()
{
return $this->address;
}
/**
* Set catId
*
* #param integer $catId
* #return Buss_owner
*/
public function setCatId($catId)
{
$this->catId = $catId;
return $this;
}
/**
* Get catId
*
* #return integer
*/
public function getCatId()
{
return $this->catId;
}
/**
* Set password
*
* #param string $password
* #return Buss_owner
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* #return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set uniqueId
*
* #param string $uniqueId
* #return Buss_owner
*/
public function setUniqueId($uniqueId)
{
$this->uniqueId = $uniqueId;
return $this;
}
/**
* Get uniqueId
*
* #return string
*/
public function getUniqueId()
{
return $this->uniqueId;
}
/**
* Set fbId
*
* #param integer $fbId
* #return Buss_owner
*/
public function setFbId($fbId)
{
$this->fbId = $fbId;
return $this;
}
/**
* Get fbId
*
* #return integer
*/
public function getFbId()
{
return $this->fbId;
}
}
I believe the problem is the underscore in the entity name.
Doctrine's naming convention is to use CamelCase which it then converts to underscores in the database. Due to this behind the scenes magic, underscores can cause problems in entity names.
Try changing the entity class name to BussOwner and calling this in the controller. If you can't change the table name you can handle this by modifying the entity annotation to:
#ORM\Table(name="buss_owner")

Symfony 2 doctrine left join

I have query
$em = $this->getDoctrine()->getManager();
$query = $em->createQueryBuilder();
$query = $em->createQueryBuilder()
->select('com', 'cit')
->from('CatalogWebBundle:ComCompany', 'com')
->leftJoin('com.cmpCity', 'cit')
->getQuery()
->setMaxResults(1);
$info = $query->getResult();
work fine, but I dont know how to get result from JOINED TABLE. I try use get method from JOINED table ENTITIES, but it not work ?
Maybe I need to ad something to ENTITIES ?
class ComCity
{
/**
* #var integer
*
* #ORM\Column(name="cit_id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $citId;
/**
* #var string
*
* #ORM\Column(name="cit_name", type="string", length=255, nullable=true)
*/
private $citName;
/**
* Get citId
*
* #return integer
*/
public function getCitId()
{
return $this->citId;
}
/**
* Set citName
*
* #param string $citName
* #return ComCity
*/
public function setCitName($citName)
{
$this->citName = $citName;
return $this;
}
/**
* Get citName
*
* #return string
*/
public function getCitName()
{
return $this->citName;
}
}
namespace Catalog\WebBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
class ComCompany
{
/**
* #var integer
*
* #ORM\Column(name="cmp_id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $cmpId;
/**
* #var string
*
* #ORM\Column(name="cmp_name", type="string", length=255, nullable=true)
*/
private $cmpName;
/**
* #var integer
*
* #ORM\Column(name="cmp_code", type="bigint", nullable=true)
*/
private $cmpCode;
/**
* #var string
*
* #ORM\Column(name="cmp_vat", type="string", length=255, nullable=true)
*/
private $cmpVat;
/**
* #var integer
*
* #ORM\Column(name="cmp_emp", type="integer", nullable=true)
*/
private $cmpEmp;
/**
* #var string
*
* #ORM\Column(name="cmp_return", type="string", length=255, nullable=true)
*/
private $cmpReturn;
/**
* #var string
*
* #ORM\Column(name="cmp_return_from", type="string", length=255, nullable=true)
*/
private $cmpReturnFrom;
/**
* #var string
*
* #ORM\Column(name="cmp_return_till", type="string", length=255, nullable=true)
*/
private $cmpReturnTill;
/**
* #var string
*
* #ORM\Column(name="cmp_address", type="string", length=255, nullable=true)
*/
private $cmpAddress;
/**
* #var integer
*
* #ORM\Column(name="cmp_phone", type="bigint", nullable=true)
*/
private $cmpPhone;
/**
* #var string
*
* #ORM\Column(name="cmp_email", type="string", length=255, nullable=true)
*/
private $cmpEmail;
/**
* #var string
*
* #ORM\Column(name="cmp_site", type="string", length=255, nullable=true)
*/
private $cmpSite;
/**
* #var string
*
* #ORM\Column(name="cmp_ceo", type="string", length=255, nullable=true)
*/
private $cmpCeo;
/**
* #var string
*
* #ORM\Column(name="cmp_register", type="string", length=255, nullable=true)
*/
private $cmpRegister;
/**
* #var string
*
* #ORM\Column(name="cmp_url", type="string", length=255, nullable=false)
*/
private $cmpUrl;
/**
* #var \Catalog\WebBundle\Entity\ComCategory
*
* #ORM\ManyToOne(targetEntity="Catalog\WebBundle\Entity\ComCategory")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="cmp_category", referencedColumnName="cat_id")
* })
*/
private $cmpCategory;
/**
* #var \Catalog\WebBundle\Entity\ComCity
*
* #ORM\ManyToOne(targetEntity="Catalog\WebBundle\Entity\ComCity")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="cmp_city", referencedColumnName="cit_id")
* })
*/
private $cmpCity;
/**
* Get cmpId
*
* #return integer
*/
public function getCmpId()
{
return $this->cmpId;
}
/**
* Set cmpName
*
* #param string $cmpName
* #return ComCompany
*/
public function setCmpName($cmpName)
{
$this->cmpName = $cmpName;
return $this;
}
/**
* Get cmpName
*
* #return string
*/
public function getCmpName()
{
return $this->cmpName;
}
/**
* Set cmpCode
*
* #param integer $cmpCode
* #return ComCompany
*/
public function setCmpCode($cmpCode)
{
$this->cmpCode = $cmpCode;
return $this;
}
/**
* Get cmpCode
*
* #return integer
*/
public function getCmpCode()
{
return $this->cmpCode;
}
/**
* Set cmpVat
*
* #param string $cmpVat
* #return ComCompany
*/
public function setCmpVat($cmpVat)
{
$this->cmpVat = $cmpVat;
return $this;
}
/**
* Get cmpVat
*
* #return string
*/
public function getCmpVat()
{
return $this->cmpVat;
}
/**
* Set cmpEmp
*
* #param integer $cmpEmp
* #return ComCompany
*/
public function setCmpEmp($cmpEmp)
{
$this->cmpEmp = $cmpEmp;
return $this;
}
/**
* Get cmpEmp
*
* #return integer
*/
public function getCmpEmp()
{
return $this->cmpEmp;
}
/**
* Set cmpReturn
*
* #param string $cmpReturn
* #return ComCompany
*/
public function setCmpReturn($cmpReturn)
{
$this->cmpReturn = $cmpReturn;
return $this;
}
/**
* Get cmpReturn
*
* #return string
*/
public function getCmpReturn()
{
return $this->cmpReturn;
}
/**
* Set cmpReturnFrom
*
* #param string $cmpReturnFrom
* #return ComCompany
*/
public function setCmpReturnFrom($cmpReturnFrom)
{
$this->cmpReturnFrom = $cmpReturnFrom;
return $this;
}
/**
* Get cmpReturnFrom
*
* #return string
*/
public function getCmpReturnFrom()
{
return $this->cmpReturnFrom;
}
/**
* Set cmpReturnTill
*
* #param string $cmpReturnTill
* #return ComCompany
*/
public function setCmpReturnTill($cmpReturnTill)
{
$this->cmpReturnTill = $cmpReturnTill;
return $this;
}
/**
* Get cmpReturnTill
*
* #return string
*/
public function getCmpReturnTill()
{
return $this->cmpReturnTill;
}
/**
* Set cmpAddress
*
* #param string $cmpAddress
* #return ComCompany
*/
public function setCmpAddress($cmpAddress)
{
$this->cmpAddress = $cmpAddress;
return $this;
}
/**
* Get cmpAddress
*
* #return string
*/
public function getCmpAddress()
{
return $this->cmpAddress;
}
/**
* Set cmpPhone
*
* #param integer $cmpPhone
* #return ComCompany
*/
public function setCmpPhone($cmpPhone)
{
$this->cmpPhone = $cmpPhone;
return $this;
}
/**
* Get cmpPhone
*
* #return integer
*/
public function getCmpPhone()
{
return $this->cmpPhone;
}
/**
* Set cmpEmail
*
* #param string $cmpEmail
* #return ComCompany
*/
public function setCmpEmail($cmpEmail)
{
$this->cmpEmail = $cmpEmail;
return $this;
}
/**
* Get cmpEmail
*
* #return string
*/
public function getCmpEmail()
{
return $this->cmpEmail;
}
/**
* Set cmpSite
*
* #param string $cmpSite
* #return ComCompany
*/
public function setCmpSite($cmpSite)
{
$this->cmpSite = $cmpSite;
return $this;
}
/**
* Get cmpSite
*
* #return string
*/
public function getCmpSite()
{
return $this->cmpSite;
}
/**
* Set cmpCeo
*
* #param string $cmpCeo
* #return ComCompany
*/
public function setCmpCeo($cmpCeo)
{
$this->cmpCeo = $cmpCeo;
return $this;
}
/**
* Get cmpCeo
*
* #return string
*/
public function getCmpCeo()
{
return $this->cmpCeo;
}
/**
* Set cmpRegister
*
* #param string $cmpRegister
* #return ComCompany
*/
public function setCmpRegister($cmpRegister)
{
$this->cmpRegister = $cmpRegister;
return $this;
}
/**
* Get cmpRegister
*
* #return string
*/
public function getCmpRegister()
{
return $this->cmpRegister;
}
/**
* Set cmpUrl
*
* #param string $cmpUrl
* #return ComCompany
*/
public function setCmpUrl($cmpUrl)
{
$this->cmpUrl = $cmpUrl;
return $this;
}
/**
* Get cmpUrl
*
* #return string
*/
public function getCmpUrl()
{
return $this->cmpUrl;
}
/**
* Set cmpCategory
*
* #param \Catalog\WebBundle\Entity\ComCategory $cmpCategory
* #return ComCompany
*/
public function setCmpCategory(\Catalog\WebBundle\Entity\ComCategory $cmpCategory = null)
{
$this->cmpCategory = $cmpCategory;
return $this;
}
/**
* Get cmpCategory
*
* #return \Catalog\WebBundle\Entity\ComCategory
*/
public function getCmpCategory()
{
return $this->cmpCategory;
}
/**
* Set cmpCity
*
* #param \Catalog\WebBundle\Entity\ComCity $cmpCity
* #return ComCompany
*/
public function setCmpCity(\Catalog\WebBundle\Entity\ComCity $cmpCity = null)
{
$this->cmpCity = $cmpCity;
return $this;
}
/**
* Get cmpCity
*
* #return \Catalog\WebBundle\Entity\ComCity
*/
public function getCmpCity()
{
return $this->cmpCity;
}
}
getResult() returns the entire set of results as an iterable array collection, not a single result. Thus, when you are using setMaxResults(1), it is wise to fetch that single result using getSingleResult():
$info = $query->getSingleResult();
If no results are returned, $info will be null. Otherwise you will be able to access the cmpCity property using:
$cmpCity = $info->getCmpCity();
Again, $cmpCity will be null if there is no cmpCity associated with the ComCompany object. If you want to get the first ComCompany object that does have an associated cmpCity, use innerJoin instead of leftJoin:
$query = $em->createQueryBuilder()
->select('com', 'cit')
->from('CatalogWebBundle:ComCompany', 'com')
->innerJoin('com.cmpCity', 'cit')
->getQuery()
->setMaxResults(1);
$info = $query->getSingleResult();
$cmpCity = $info->getCmpCity();
This might be related to the issue when you combine leftJoin and setMaxResults.
There is already answers on how you should do your query : https://stackoverflow.com/a/14886847/3726645

ManyToOne in Symfony2 + Doctrine

I want to create a relation betwen 4 tables.
page (table for pages, fields: name, uri, status)
block (table for blocks, here i can have multipy records for specific page, fields: id, parrent_id, template)
block_content (table for contents of each block, here can have mulitpay records for a specific block, fields: id, block_id, lang, content)
block_relation (holding relations betwen page table and block table, fields: id, page_id, block_id)
How can i create relations betwen those tables.
Till now i've created this:
block_content:
<?php
namespace Casewise\Bundle\DispatcherBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* BlockRelation
*
* #ORM\Table(name="block_relation")
* #ORM\Entity
*/
class BlockRelation
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="Casewise\Bundle\PageBundle\Entity\Page", inversedBy="block_relation")
* #ORM\JoinColumn(name="page_id", referencedColumnName="page_id", nullable=FALSE)
*/
private $pageid;
/**
* #ORM\ManyToOne(targetEntity="Casewise\Bundle\CmsBundle\Entity\Block", inversedBy="block_relation")
* #ORM\JoinColumn(name="block_id", referencedColumnName="block_id", nullable=FALSE)
*/
private $blockid;
/** SETTERS AND GETTERS */
/**
* Gets the value of id.
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Sets the value of id.
*
* #param integer $id the id
*
* #return self
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* Gets the value of pageid.
*
* #return integer
*/
public function getPageid()
{
return $this->pageid;
}
/**
* Sets the value of pageid.
*
* #param integer $pageid the pageid
*
* #return self
*/
public function setPageid($pageid)
{
$this->pageid = $pageid;
return $this;
}
/**
* Gets the value of blockid.
*
* #return integer
*/
public function getBlockid()
{
return $this->blockid;
}
/**
* Sets the value of blockid.
*
* #param integer $blockid the blockid
*
* #return self
*/
public function setBlockid($blockid)
{
$this->blockid = $blockid;
return $this;
}
}
block:
namespace Casewise\Bundle\CmsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
//use Doctrine\Common\Collections\ArrayCollection;
/**
* Block
*
* #ORM\Table(name="block")
* #ORM\Entity
*/
class Block
{
/**
* #var integer
*
* #ORM\Column(name="block_id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $blockid;
/**
* #var integer
*
* #ORM\Column(name="parrent_id", type="integer")
*/
private $parrentid;
/**
* #var string
*
* #ORM\Column(name="template", type="string", length=150)
*/
private $template;
/**
* #var string
*
* #ORM\Column(name="status", type="boolean", options={"default" = 1})
*/
private $status;
/** SETTERS AND GETTERS */
/**
* Gets the value of blockid.
*
* #return integer
*/
public function getBlockid()
{
return $this->blockid;
}
/**
* Sets the value of blockid.
*
* #param integer $blockid the blockid
*
* #return self
*/
public function setBlockid($blockid)
{
$this->blockid = $blockid;
return $this;
}
/**
* Gets the value of parrentid.
*
* #return integer
*/
public function getParrentid()
{
return $this->parrentid;
}
/**
* Sets the value of parrentid.
*
* #param integer $parrentid the parrentid
*
* #return self
*/
public function setParrentid($parrentid)
{
$this->parrentid = $parrentid;
return $this;
}
/**
* Gets the value of template.
*
* #return string
*/
public function getTemplate()
{
return $this->template;
}
/**
* Sets the value of template.
*
* #param string $template the template
*
* #return self
*/
public function setTemplate($template)
{
$this->template = $template;
return $this;
}
/**
* Gets the value of status.
*
* #return string
*/
public function getStatus()
{
return $this->status;
}
/**
* Sets the value of status.
*
* #param string $status the status
*
* #return self
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
}
BlockContent:
<?php
namespace Casewise\Bundle\CmsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Block
*
* #ORM\Table(name="block_content")
* #ORM\Entity
*/
class BlockContent
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="Casewise\Bundle\CmsBundle\Entity\Block", inversedBy="block_id")
* #ORM\JoinColumn(name="block_id", referencedColumnName="block_id", nullable=FALSE)
*/
private $blockid;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=150)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="language", type="string", length=15)
*/
private $language;
/**
* #var string
*
* #ORM\Column(name="content", type="text")
*/
private $content;
/** SETTERS AND GETTERS */
/**
* Gets the value of id.
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Sets the value of id.
*
* #param integer $id the id
*
* #return self
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* Gets the value of blockid.
*
* #return integer
*/
public function getBlockid()
{
return $this->blockid;
}
/**
* Sets the value of blockid.
*
* #param integer $blockid the blockid
*
* #return self
*/
public function setBlockid($blockid)
{
$this->blockid = $blockid;
return $this;
}
/**
* Gets the value of name.
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Sets the value of name.
*
* #param string $name the name
*
* #return self
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Gets the value of language.
*
* #return string
*/
public function getLanguage()
{
return $this->language;
}
/**
* Sets the value of language.
*
* #param string $language the language
*
* #return self
*/
public function setLanguage($language)
{
$this->language = $language;
return $this;
}
/**
* Gets the value of content.
*
* #return string
*/
public function getContent()
{
return $this->content;
}
/**
* Sets the value of content.
*
* #param string $content the content
*
* #return self
*/
public function setContent($content)
{
$this->content = $content;
return $this;
}
}
Page
<?php
namespace Casewise\Bundle\PageBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
//use Doctrine\Common\Collections\ArrayCollection;
/**
* Page
*
* #ORM\Table(name="page")
* #ORM\Entity
*/
class Page
{
/**
* #var integer
*
* #ORM\Column(name="page_id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $pageid;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="uri", type="string", length=255)
*/
private $uri;
/**
* #var string
*
* #ORM\Column(name="status", type="boolean", options={"default" = 1})
*/
private $status;
/** SETTERS AND GETTERS */
/**
* Gets the value of id.
*
* #return integer
*/
public function getPageId()
{
return $this->pageid;
}
/**
* Sets the value of id.
*
* #param integer $id the id
*
* #return self
*/
public function setPageId($pageid)
{
$this->pageid = $pageid;
return $this;
}
/**
* Gets the value of name.
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Sets the value of name.
*
* #param string $name the name
*
* #return self
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Gets the value of uri.
*
* #return string
*/
public function getUri()
{
return $this->uri;
}
/**
* Sets the value of uri.
*
* #param string $uri the uri
*
* #return self
*/
public function setUri($uri)
{
$this->uri = $uri;
return $this;
}
/**
* Gets the value of status.
*
* #return string
*/
public function getStatus()
{
return $this->status;
}
/**
* Sets the value of status.
*
* #param string $status the status
*
* #return self
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
}
UPDATE:
I've update shema with: doctrine:schema:update --force
And when i request the Relation Entity and give him the pageid i need to get all related blocks to the specifc page, but it returns an huge object in which contains symfony2 specific objects(object with over 3000 lines), like requests, response and other objects which are not related to my request.
This is how i request entity:
$blocks = $this->getDoctrine()
->getRepository('CasewiseDispatcherBundle:BlockRelation')
->findByPageid(1);
echo '<pre>';
print_r($blocks);
echo '</pre>';

Resources