r***@public.gmane.org
2013-07-11 19:49:53 UTC
Hi,
I'm trying to implement translation through the *
StofDoctrineExtensionsBundle* I added this on the composer.json:
"stof/doctrine-extensions-bundle": "~***@dev",
On the *config.yml* I have
# Doctrine Configuration
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
# if using pdo_sqlite as your database driver, add the path in
parameters.yml
# e.g. database_path: %kernel.root_dir%/data/data.db3
# path: %database_path%
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
mappings:
StofDoctrineExtensionsBundle: ~
# Swiftmailer Configuration
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
spool: { type: memory }
#Stof doctrine extension
stof_doctrine_extensions:
default_locale: en_US
orm:
default:
tree: false # not needed: listeners are not enabled by default
timestampable: true
sortable: true
sluggable: true
translatable: true
I created three entities to try this:
<?php
namespace RSantellan\SitioBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* Category
*
* @ORM\Table(name="rs_category")
*
@ORM\Entity(repositoryClass="Gedmo\Sortable\Entity\Repository\SortableRepository")
* @author Rodrigo Santellan
*/
class Category
{
/**
* @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=255)
*/
private $name;
/**
* @Gedmo\SortablePosition
* @ORM\Column(type="integer")
*/
protected $orden;
/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(type="string", unique=true)
*/
private $slug;
/**
* var Projects
* @ORM\OneToMany(targetEntity="Project", mappedBy="category")
*/
private $projects;
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Category
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
public function __construct() {
$this->projects = new ArrayCollection();
}
public function __toString() {
return $this->getName();
}
/**
* Add projects
*
* @param \RSantellan\SitioBundle\Entity\Project $projects
* @return Category
*/
public function addProject(\RSantellan\SitioBundle\Entity\Project
$projects)
{
$this->projects[] = $projects;
return $this;
}
/**
* Remove projects
*
* @param \RSantellan\SitioBundle\Entity\Project $projects
*/
public function removeProject(\RSantellan\SitioBundle\Entity\Project
$projects)
{
$this->projects->removeElement($projects);
}
/**
* Get projects
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getProjects()
{
return $this->projects;
}
/**
* Set orden
*
* @param integer $orden
* @return Category
*/
public function setOrden($orden)
{
$this->orden = $orden;
return $this;
}
/**
* Get orden
*
* @return integer
*/
public function getOrden()
{
return $this->orden;
}
/**
* Set slug
*
* @param string $slug
* @return Category
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* @return string
*/
public function getSlug()
{
return $this->slug;
}
}
<?php
namespace RSantellan\SitioBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Translatable\Translatable;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Project
*
*
@ORM\Entity(repositoryClass="Gedmo\Sortable\Entity\Repository\SortableRepository")
* @ORM\Table(name="rs_project")
*
@Gedmo\TranslationEntity(class="RSantellan\SitioBundle\Entity\ProjectTranslation")
* @author Rodrigo Santellan
*/
class Project{
/**
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*
*/
protected $id;
/**
* @Gedmo\Translatable
* @ORM\Column(type="string", length=100)
*/
protected $name;
/**
*
* @ORM\Column(type="string", length=100, nullable=true)
*/
protected $cliente;
/**
* @Gedmo\Translatable
* @ORM\Column(type="text", nullable=true)
*/
protected $tipo_de_trabajo;
/**
* @Gedmo\Translatable
* @ORM\Column(type="text", nullable=true)
*/
protected $description;
/**
* @Gedmo\SortablePosition
* @ORM\Column(type="integer")
*/
protected $orden;
/**
* @Gedmo\Locale
* Used locale to override Translation listener`s locale
* this is not a mapped field of entity metadata, just a simple property
*/
private $locale;
/**
*
* @ORM\ManyToOne(targetEntity="Category", inversedBy="projects")
* @ORM\JoinColumn(name="category_id", referencedColumnName="id")
* @Assert\NotBlank()
*
*/
protected $category;
/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(type="string", unique=true)
*/
protected $slug;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Project
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set cliente
*
* @param string $cliente
* @return Project
*/
public function setCliente($cliente)
{
$this->cliente = $cliente;
return $this;
}
/**
* Get cliente
*
* @return string
*/
public function getCliente()
{
return $this->cliente;
}
/**
* Set tipo_de_trabajo
*
* @param string $tipoDeTrabajo
* @return Project
*/
public function setTipoDeTrabajo($tipoDeTrabajo)
{
$this->tipo_de_trabajo = $tipoDeTrabajo;
return $this;
}
/**
* Get tipo_de_trabajo
*
* @return string
*/
public function getTipoDeTrabajo()
{
return $this->tipo_de_trabajo;
}
/**
* Set description
*
* @param string $description
* @return Project
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set orden
*
* @param integer $orden
* @return Project
*/
public function setOrden($orden)
{
$this->orden = $orden;
return $this;
}
/**
* Get orden
*
* @return integer
*/
public function getOrden()
{
return $this->orden;
}
/**
* Set category
*
* @param \RSantellan\SitioBundle\Entity\Category $category
* @return Project
*/
public function setCategory(\RSantellan\SitioBundle\Entity\Category
$category = null)
{
$this->category = $category;
return $this;
}
/**
* Get category
*
* @return \RSantellan\SitioBundle\Entity\Category
*/
public function getCategory()
{
return $this->category;
}
/**
* Set slug
*
* @param string $slug
* @return Project
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* @return string
*/
public function getSlug()
{
return $this->slug;
}
public function getFullClassName()
{
return get_class($this);
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
}
Doing *php app/console generate:doctrine:entities* *RSantellanSitioBundle*generated this new class
<?php
namespace RSantellan\SitioBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation;
/**
* @ORM\Table(name="rs_project_translations", indexes={
* @ORM\Index(name="rs_project_translation_idx", columns={"locale",
"object_class", "field", "foreign_key"})
* })
*
@ORM\Entity(repositoryClass="Gedmo\Translatable\Entity\Repository\TranslationRepository")
* @author rodrigo
*/
class ProjectTranslation extends AbstractTranslation
{
//put your code here
/**
*
* @var integer
*
*/
protected $id;
/**
* @var string
*/
protected $locale;
/**
* @var string
*/
protected $objectClass;
/**
* @var string
*/
protected $field;
/**
* @var string
*/
protected $foreignKey;
/**
* @var string
*/
protected $content;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set locale
*
* @param string $locale
* @return ProjectTranslation
*/
public function setLocale($locale)
{
$this->locale = $locale;
return $this;
}
/**
* Get locale
*
* @return string
*/
public function getLocale()
{
return $this->locale;
}
/**
* Set objectClass
*
* @param string $objectClass
* @return ProjectTranslation
*/
public function setObjectClass($objectClass)
{
$this->objectClass = $objectClass;
return $this;
}
/**
* Get objectClass
*
* @return string
*/
public function getObjectClass()
{
return $this->objectClass;
}
/**
* Set field
*
* @param string $field
* @return ProjectTranslation
*/
public function setField($field)
{
$this->field = $field;
return $this;
}
/**
* Get field
*
* @return string
*/
public function getField()
{
return $this->field;
}
/**
* Set foreignKey
*
* @param string $foreignKey
* @return ProjectTranslation
*/
public function setForeignKey($foreignKey)
{
$this->foreignKey = $foreignKey;
return $this;
}
/**
* Get foreignKey
*
* @return string
*/
public function getForeignKey()
{
return $this->foreignKey;
}
/**
* Set content
*
* @param string $content
* @return ProjectTranslation
*/
public function setContent($content)
{
$this->content = $content;
return $this;
}
/**
* Get content
*
* @return string
*/
public function getContent()
{
return $this->content;
}
}
Now I'm trying to generate the doctrine cruds *php app/console
generate:doctrine:crud --entity="RSantellanSitioBundle:Project"*
And what I get is:
[Doctrine\ORM\Mapping\MappingException]
No identifier/primary key specified for Entity
"RSantellan\SitioBundle\Entity\ProjectTranslation" sub class of
"Gedmo\Translatable\Entity\Mappe
dSuperclass\AbstractTranslation". Every Entity must have an
identifier/primary key.
I need to implement translations of the Entities on the database. I done a
lot of projects with multi language in Symfony 1.4 but trying to migrate
one too Symfony 2.3 is become a really hard work, because all the thing
that where given in Symfony 1.4 are gone...
Any idea, any help will be really appreciated.
Regards
--
--
If you want to report a vulnerability issue on Symfony, please read the procedure on http://symfony.com/security
You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
---
You received this message because you are subscribed to the Google Groups "Symfony2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to symfony2+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
I'm trying to implement translation through the *
StofDoctrineExtensionsBundle* I added this on the composer.json:
"stof/doctrine-extensions-bundle": "~***@dev",
On the *config.yml* I have
# Doctrine Configuration
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
# if using pdo_sqlite as your database driver, add the path in
parameters.yml
# e.g. database_path: %kernel.root_dir%/data/data.db3
# path: %database_path%
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
mappings:
StofDoctrineExtensionsBundle: ~
# Swiftmailer Configuration
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
spool: { type: memory }
#Stof doctrine extension
stof_doctrine_extensions:
default_locale: en_US
orm:
default:
tree: false # not needed: listeners are not enabled by default
timestampable: true
sortable: true
sluggable: true
translatable: true
I created three entities to try this:
<?php
namespace RSantellan\SitioBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* Category
*
* @ORM\Table(name="rs_category")
*
@ORM\Entity(repositoryClass="Gedmo\Sortable\Entity\Repository\SortableRepository")
* @author Rodrigo Santellan
*/
class Category
{
/**
* @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=255)
*/
private $name;
/**
* @Gedmo\SortablePosition
* @ORM\Column(type="integer")
*/
protected $orden;
/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(type="string", unique=true)
*/
private $slug;
/**
* var Projects
* @ORM\OneToMany(targetEntity="Project", mappedBy="category")
*/
private $projects;
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Category
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
public function __construct() {
$this->projects = new ArrayCollection();
}
public function __toString() {
return $this->getName();
}
/**
* Add projects
*
* @param \RSantellan\SitioBundle\Entity\Project $projects
* @return Category
*/
public function addProject(\RSantellan\SitioBundle\Entity\Project
$projects)
{
$this->projects[] = $projects;
return $this;
}
/**
* Remove projects
*
* @param \RSantellan\SitioBundle\Entity\Project $projects
*/
public function removeProject(\RSantellan\SitioBundle\Entity\Project
$projects)
{
$this->projects->removeElement($projects);
}
/**
* Get projects
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getProjects()
{
return $this->projects;
}
/**
* Set orden
*
* @param integer $orden
* @return Category
*/
public function setOrden($orden)
{
$this->orden = $orden;
return $this;
}
/**
* Get orden
*
* @return integer
*/
public function getOrden()
{
return $this->orden;
}
/**
* Set slug
*
* @param string $slug
* @return Category
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* @return string
*/
public function getSlug()
{
return $this->slug;
}
}
<?php
namespace RSantellan\SitioBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Translatable\Translatable;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Project
*
*
@ORM\Entity(repositoryClass="Gedmo\Sortable\Entity\Repository\SortableRepository")
* @ORM\Table(name="rs_project")
*
@Gedmo\TranslationEntity(class="RSantellan\SitioBundle\Entity\ProjectTranslation")
* @author Rodrigo Santellan
*/
class Project{
/**
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*
*/
protected $id;
/**
* @Gedmo\Translatable
* @ORM\Column(type="string", length=100)
*/
protected $name;
/**
*
* @ORM\Column(type="string", length=100, nullable=true)
*/
protected $cliente;
/**
* @Gedmo\Translatable
* @ORM\Column(type="text", nullable=true)
*/
protected $tipo_de_trabajo;
/**
* @Gedmo\Translatable
* @ORM\Column(type="text", nullable=true)
*/
protected $description;
/**
* @Gedmo\SortablePosition
* @ORM\Column(type="integer")
*/
protected $orden;
/**
* @Gedmo\Locale
* Used locale to override Translation listener`s locale
* this is not a mapped field of entity metadata, just a simple property
*/
private $locale;
/**
*
* @ORM\ManyToOne(targetEntity="Category", inversedBy="projects")
* @ORM\JoinColumn(name="category_id", referencedColumnName="id")
* @Assert\NotBlank()
*
*/
protected $category;
/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(type="string", unique=true)
*/
protected $slug;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Project
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set cliente
*
* @param string $cliente
* @return Project
*/
public function setCliente($cliente)
{
$this->cliente = $cliente;
return $this;
}
/**
* Get cliente
*
* @return string
*/
public function getCliente()
{
return $this->cliente;
}
/**
* Set tipo_de_trabajo
*
* @param string $tipoDeTrabajo
* @return Project
*/
public function setTipoDeTrabajo($tipoDeTrabajo)
{
$this->tipo_de_trabajo = $tipoDeTrabajo;
return $this;
}
/**
* Get tipo_de_trabajo
*
* @return string
*/
public function getTipoDeTrabajo()
{
return $this->tipo_de_trabajo;
}
/**
* Set description
*
* @param string $description
* @return Project
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set orden
*
* @param integer $orden
* @return Project
*/
public function setOrden($orden)
{
$this->orden = $orden;
return $this;
}
/**
* Get orden
*
* @return integer
*/
public function getOrden()
{
return $this->orden;
}
/**
* Set category
*
* @param \RSantellan\SitioBundle\Entity\Category $category
* @return Project
*/
public function setCategory(\RSantellan\SitioBundle\Entity\Category
$category = null)
{
$this->category = $category;
return $this;
}
/**
* Get category
*
* @return \RSantellan\SitioBundle\Entity\Category
*/
public function getCategory()
{
return $this->category;
}
/**
* Set slug
*
* @param string $slug
* @return Project
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* @return string
*/
public function getSlug()
{
return $this->slug;
}
public function getFullClassName()
{
return get_class($this);
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
}
Doing *php app/console generate:doctrine:entities* *RSantellanSitioBundle*generated this new class
<?php
namespace RSantellan\SitioBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation;
/**
* @ORM\Table(name="rs_project_translations", indexes={
* @ORM\Index(name="rs_project_translation_idx", columns={"locale",
"object_class", "field", "foreign_key"})
* })
*
@ORM\Entity(repositoryClass="Gedmo\Translatable\Entity\Repository\TranslationRepository")
* @author rodrigo
*/
class ProjectTranslation extends AbstractTranslation
{
//put your code here
/**
*
* @var integer
*
*/
protected $id;
/**
* @var string
*/
protected $locale;
/**
* @var string
*/
protected $objectClass;
/**
* @var string
*/
protected $field;
/**
* @var string
*/
protected $foreignKey;
/**
* @var string
*/
protected $content;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set locale
*
* @param string $locale
* @return ProjectTranslation
*/
public function setLocale($locale)
{
$this->locale = $locale;
return $this;
}
/**
* Get locale
*
* @return string
*/
public function getLocale()
{
return $this->locale;
}
/**
* Set objectClass
*
* @param string $objectClass
* @return ProjectTranslation
*/
public function setObjectClass($objectClass)
{
$this->objectClass = $objectClass;
return $this;
}
/**
* Get objectClass
*
* @return string
*/
public function getObjectClass()
{
return $this->objectClass;
}
/**
* Set field
*
* @param string $field
* @return ProjectTranslation
*/
public function setField($field)
{
$this->field = $field;
return $this;
}
/**
* Get field
*
* @return string
*/
public function getField()
{
return $this->field;
}
/**
* Set foreignKey
*
* @param string $foreignKey
* @return ProjectTranslation
*/
public function setForeignKey($foreignKey)
{
$this->foreignKey = $foreignKey;
return $this;
}
/**
* Get foreignKey
*
* @return string
*/
public function getForeignKey()
{
return $this->foreignKey;
}
/**
* Set content
*
* @param string $content
* @return ProjectTranslation
*/
public function setContent($content)
{
$this->content = $content;
return $this;
}
/**
* Get content
*
* @return string
*/
public function getContent()
{
return $this->content;
}
}
Now I'm trying to generate the doctrine cruds *php app/console
generate:doctrine:crud --entity="RSantellanSitioBundle:Project"*
And what I get is:
[Doctrine\ORM\Mapping\MappingException]
No identifier/primary key specified for Entity
"RSantellan\SitioBundle\Entity\ProjectTranslation" sub class of
"Gedmo\Translatable\Entity\Mappe
dSuperclass\AbstractTranslation". Every Entity must have an
identifier/primary key.
I need to implement translations of the Entities on the database. I done a
lot of projects with multi language in Symfony 1.4 but trying to migrate
one too Symfony 2.3 is become a really hard work, because all the thing
that where given in Symfony 1.4 are gone...
Any idea, any help will be really appreciated.
Regards
--
--
If you want to report a vulnerability issue on Symfony, please read the procedure on http://symfony.com/security
You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
---
You received this message because you are subscribed to the Google Groups "Symfony2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to symfony2+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.