我想用记录信息返回\ Symfony\Component\HttpFoundation\JsonResponse,但我需要将其作为数组传递.
目前我这样做:
$repository = $this->getDoctrine()->getRepository('XxxYyyZzzBundle:Products');
$product = $repositorio->findOneByBarCode($value);
Run Code Online (Sandbox Code Playgroud)
但现在$ product是一个实体,包含我想要的所有东西,但是作为对象.我怎么能把它们转换成数组?
我在某处读到了我需要使用"Doctrine\ORM\Query :: HYDRATE_ARRAY",但似乎'findOneBy'魔术过滤器不接受这样的参数.
*
* @return object|null The entity instance or NULL if the entity can not be found.
*/
public function findOneBy(array $criteria, array $orderBy = null)
Run Code Online (Sandbox Code Playgroud)
好,多亏了dbrumann,我得到了它的工作,只想添加完整的工作示例.
似乎 - > from()需要2个参数.
$em = $this->getDoctrine()->getManager();
$query = $em->createQueryBuilder()
->select('p')
->from('XxxYyyZzzBundle:Products','p')
->where('p.BarCode = :barcode')
->setParameter('barcode', $value)
->getQuery()
;
$data = $query->getSingleResult(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);
Run Code Online (Sandbox Code Playgroud) 在我的工作中,他们已经使用了一个经过修改的Bootstrap模板,它可以很好地处理Symfony2中的所有内容,但我希望Symfony2生成的CRUD具有Bootstrap 3结构,因此它可以通过它进行样式设置.
目前我发现:
捆绑"问题好"的问题是我不知道是否有一些提供此功能的"主要供应商"捆绑包?
基本上我的问题是,如果你知道一个Bundle生成带有Bootstrap 3结构的CRUD?