2014-04-06 3 views
0

저는 Zend2를 처음 사용하여 두 개의 테이블 게이트 객체를 결합하고자합니다.Zend2 결합 테이블 게이트 배열

두 테이블이 있습니다. 가격과 크기가 있습니다. 모든 가격에는 여러 크기가 있습니다. 이 테이블을 배열에 결합하고자하므로 가격을 가격으로 나열 할 수 있습니다. 내가 (그래서의 크기없이) 가격을 표시하는 방법

public function getPricesbyJewel($jewel) 
{ 
    $rowset = $this->tableGateway->select(array('jewelid' => $jewel)); 
    return $rowset; 
} 

내 SizesTable.php

:

array(
     1 => array(
       'price' => 45, 
       'description' => 'Lorem ipsum', 
       'sizes' => array(
        1 => '16', 
        2 => '17', 
        3 => '20', 
        4 => '21' 
       ) 
     ), 
     2 => array(
       'price' => 50, 
       'description' => 'Lorem ipsum', 
       'sizes' => array(
        1 => '34', 
        2 => '12', 
        3 => '21', 
        4 => '50' 
       ) 
     ) 
    ) 

내 PricesTable.php : 예를 들어

$jewelPrices = array('jewelryPrices' => $this->getPricesTable()->getPricesbyJewel($jewel->id)); 
$jewelSizes = array('jewelrySizes' => $this->getSizesTable()->getSizesbyPrice($priceID); 

크기를 컨트롤러에있는 테이블의 배열로 가격에 나열하는 방법은 무엇입니까?

+1

이 시도 http://stackoverflow.com/questions/14354802/tablegateway-with -multiple-from-tables? rq = 1 – Ruwantha

답변

0

하는 내부로 고정 가입 :

PriceTable.php에게

public function getPricesbyJewel($jewel) 
{ 
    $sql = new Sql($this->tableGateway->getAdapter()); 

    $select = $sql->select(); 
    $select->from('jewelry_prices') 
     ->join('jewelry_sizes', 'jewelry_prices.id=jewelry_sizes.priceID') 
     ->where('jewelry_prices.jewelid='.$jewel); 
    $resultSet = $this->tableGateway->selectWith($select); 
    return $resultSet; 
} 

컨트롤러 :

$prices = array('jewelryPrices' => array()); 
foreach($this->getPricesTable()->getPricesbyJewel($jewel->id) as $key => $price){ 
      if(!array_key_exists($price->priceID, $prices['jewelryPrices'])){ 
       $prices['jewelryPrices'][$price->priceID] = array(
        'orderNote' => $price->orderNote, 
        'price'  => $price->price, 
        'description' => $price->description, 
        'sizes'  => array() 
       ); 
       array_push($prices['jewelryPrices'][$price->priceID]['sizes'], $price->size); 
      } else { 
       array_push($prices['jewelryPrices'][$price->priceID]['sizes'], $price->size); 
      } 
     }