Php 访问对象的细枝变量数组
我有一个twig变量及其包含:Php 访问对象的细枝变量数组,php,symfony,twig,Php,Symfony,Twig,我有一个twig变量及其包含: object(Video\VideoBundle\Entity\Relacionado)[366] protected 'video' => object(Video\VideoBundle\Entity\Video)[339] private 'id' => int 1 **protected 'categoria' => object(Proxies\__CG__\Video\VideoBundle\E
object(Video\VideoBundle\Entity\Relacionado)[366]
protected 'video' =>
object(Video\VideoBundle\Entity\Video)[339]
private 'id' => int 1
**protected 'categoria' =>
object(Proxies\__CG__\Video\VideoBundle\Entity\Categoria)[397]
public '__initializer__' =>
object(Closure)[388]
public '__cloner__' =>
object(Closure)[389]
public '__isInitialized__' => boolean true
private 'id' (Video\VideoBundle\Entity\Categoria) => int 1**
我想访问TWIG中的category id变量
我的小枝文件:
<div class="Descripcion">
<h1> {{ video.name }} ( {{ video.duracion}} min ) </h1>
{% for tag in tags %}
{{ dump(tag) }}
{% endfor %}
</div>
还有我的查询dql
public function findCategoriaVideo($idvideo)
{
$em = $this->getEntityManager();
$dql = 'SELECT c,r FROM VideoBundle:Relacionado r INNER JOIN r.video c WHERE r.video = :id';
$consulta = $em->createQuery($dql);
$consulta->setParameter('id',$idvideo);
return $consulta->getResult();
}
我认为我用错了我的社交圈:
/**
* Relacionado
*
* @ORM\Table()
* @ORM\Entity
* @ORM\Entity(repositoryClass="Video\VideoBundle\Entity\RelacionadoRepository")
*/
class Relacionado
{
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="Video\VideoBundle\Entity\Video")
*/
protected $video;
/**
* @ORM\Id
* @ORM\ManyToOne (targetEntity = "Video\VideoBundle\Entity\Categoria")
*/
protected $categoria;
class Categoria
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\OneToMany (targetEntity = "Video\VideoBundle\Entity\Relacionado", mappedBy = "Categoria")
*/
private $id;
class Video
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
在表Relacionado I中,将视频与每个视频相关的类别相关联
但我不知道,因为结果视频是正确的,但类别否!:(
我无法访问实体Categoria,因为其映射不正确:
protected 'categoria' =>
object(Proxies\__CG__\Video\VideoBundle\Entity\Categoria)[397]
如果细枝变量的名称为entity,则可以使用以下命令访问类别:
{{ entity.getCategory }}
未找到:
{{ dump(tag.getCategoria) }}
or
tag.categoria.id
任何发现
ContextErrorException: Notice: Undefined property: Video\VideoBundle\Entity\Relacionado::$Categoria in C:\wamp\www\video\src\Video\VideoBundle\Entity\Relacionado.php line 45
但是我已经在我的实体Relacionado中定义了这个属性
class Relacionado
{
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="Video\VideoBundle\Entity\Video")
*/
protected $video;
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="Video\VideoBundle\Entity\Categoria")
*/
protected $categoria;
我认为问题可能在于:
*protected 'categoria' =>
object(Proxies\__CG__\Video\VideoBundle\Entity\Categoria)[397]
为什么要使用代理?我已经解决了我的问题!
问题在于:
public function findCategoriaVideo($idvideo)
{
$em = $this->getEntityManager();
$dql = 'SELECT r,c FROM VideoBundle:Relacionado r JOIN r.categoria c WHERE r.video = :id';
$consulta = $em->createQuery($dql);
$consulta->setParameter('id',$idvideo);
//$consulta->setMaxResults(8);
return $consulta->getResult();
}
我的班级:
class Relacionado
{
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity = "Video\VideoBundle\Entity\Categoria")
* @ORM\JoinColumn(name="categoria_id", referencedColumnName="id")
*/
protected $categoria;
/**
* @ORM\Id
* @ORM\ManyToOne (targetEntity = "Video\VideoBundle\Entity\Video")
* @ORM\JoinColumn(name="video_id", referencedColumnName="id")
**/
protected $video;
class Categoria
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\ManyToOne(targetEntity="Video\VideoBundle\Entity\Relacionado")
* @ORM\JoinColumn(name="id", referencedColumnName="categoria_id")
*
*/
我可以在哪里访问我的分类对象
非常感谢大家您转储了什么对象?如果您发布了将对象返回到细枝文件和细枝文件的控制器,这会有所帮助。Victor我转储了变量选项卡,它的变量是我渲染的。Plendonia我已经发布了信息!您不能也只使用{entity.categia.id}?{{entity.getCategory}和{{entity.category}如果您使用的是标准实体模板,则在twig中的含义相同。假设您具有stock getId函数,则joe42是正确的。Creo que estoy usando mis malas Asociacones de entidades:
class Relacionado
{
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity = "Video\VideoBundle\Entity\Categoria")
* @ORM\JoinColumn(name="categoria_id", referencedColumnName="id")
*/
protected $categoria;
/**
* @ORM\Id
* @ORM\ManyToOne (targetEntity = "Video\VideoBundle\Entity\Video")
* @ORM\JoinColumn(name="video_id", referencedColumnName="id")
**/
protected $video;
class Categoria
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\ManyToOne(targetEntity="Video\VideoBundle\Entity\Relacionado")
* @ORM\JoinColumn(name="id", referencedColumnName="categoria_id")
*
*/