I'm working on my first project on Symfony2. I have some problems with basic actions. I've generated entity of my table:
CREATE TABLE IF NOT EXISTS `product_category` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
Now I want to select all rows from this table. How should I do that? I tried to add new method in my entity.
public function getAll()
{
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery(
'SELECT *
FROM product_category'
);
return $query->getResult();
}
... but I'm pretty sure that this is bad way cause I would have to use this method in context of concrete entity. Any tips?