PHP-CodeIgniter到Symfony2与Doctrine2

我真的很难将这个查询转换为Doctrine:

public function get_order($id)
{
    $this->db->select('*');
    $this->db->from('tbl_orderline');
    $this->db->join('tbl_order', 'tbl_order.orderNo = tbl_orderline.orderNo');
    $this->db->join('tbl_customer', 'tbl_customer.customerNo = tbl_order.customerNo');
    $this->db->join('tbl_product', 'tbl_product.productNo = tbl_orderline.productNo');
    $this->db->where('tbl_order.orderNo', $id);

    $query = $this->db->get();
    return $query->result_array();
}

你能帮我这个忙吗?
有什么建议么?谢谢

解决方法:

// if you're currently in custom Repository class then:
$qb = $this->createQueryBuilder('ol');

// if you're in a controller, then should be:
$qb = $em->getRepository('AppBundle:OrderLine')->createQueryBuilder('ol'); // Or whatever your bundle name is.

// query alias legend:

// ol - order line
// o - order
// c - customer
// p - product

// Your query builder should look something like this:

$qb
    ->addSelect('o, c, p')
    ->leftJoin('ol.order', 'o') // this is your relation with [order]
    ->leftJoin('o.customer', 'c') // this is your relation with [customer] from [order]
    ->leftJoin('ol.product', 'p') // this is your relation with [product] from [order line]
    ->where($qb->expr()->eq('ol.id', ':orderLineId')
    ->setParameter('orderLineId', $id)
    ->getQuery()
    ->getOneOrNullResult();

注意:

由于您未提供任何实体映射,因此这完全是个意外.您很可能会更改此查询中的属性,但是至少,它应该为您提供所需的开始.

如果您不了解某些内容,请随时询问.

上一篇:用php中的dropdownlistbox绑定数据


下一篇:php-CodeIgniter-无法通过数组进行查看