class DBGlobalsExtension extends \Twig_Extension
{
protected $em;
public function __construct(EntityManager $em)
{
$this->em = $em;
}
public function getGlobals()
{
return array (
"ListCategories" => $this->em->getRepository('BloggerBackendBundle:Categories')->findAll()
);
}
public function getName()
{
return "BloggerFrontendBundle:DBGlobalsExtension";
}
}
services:
blogger.twig.db_globals_extension:
class: Blogger\FrontendBundle\Twig\Extension\DBGlobalsExtension
arguments: ['@doctrine.orm.entity_manager']
tags:
- { name: twig.extension }
twig:
globals:
myGlobaService: "@blogger.twig.db_globals_extension"
{% for item in myGlobaService.Globals %}
{{ item.name }}
{% endfor %}
{% for item in myGlobaService %}
{% for itemList in item.Globals %}
{{ itemList.name }}
{% endfor %}
{% endfor %}
class Categories
{
/**
* var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* var string
*
* @ORM\Column(name="name", type="string", length=255, nullable=true)
*/
private $name;
/**
* var int
*
* @ORM\Column(name="subCategories_id", type="integer", nullable=true)
*/
private $subCategoriesId;
/**
* Get id
*
* return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* return Categories
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* return string
*/
public function getName()
{
return $this->name;
}
/**
* Set subCategoriesId
*
* @param integer $subCategoriesId
*
* return Categories
*/
public function setSubCategoriesId($subCategoriesId)
{
$this->subCategoriesId = $subCategoriesId;
return $this;
}
/**
* Get subCategoriesId
*
* return int
*/
public function getSubCategoriesId()
{
return $this->subCategoriesId;
}
}
findAll()
в массив. Попробуйте сделать просто return $this->em->getRepository('BloggerBackendBundle:Categories')->findAll()