2016-06-18 5 views
0

にクエリを結合するカスタムで助けを必要とし、それらの列に私はZendの2は、複数の列の表示とクエリに参加して混乱していますZend Frameworkに2

を表示することができませんでしStudTable.php

public function custom_query() { 
     $select = new Select(); 
     $select->from(array('s' => 'stud')); 
     $select->columns(array('s.id','a.artist', 's.name', 's.sem','s.age')); 
     //$select->where(array('id' => 14)); 

     $select->join(array('a' => 'album'), 
        'a.id = s.album_id'); 
     $select->order('s.id DESC'); 
     $select->limit(5); 

     return $resultSet = $this->tableGateway->selectWith($select); 
    } 

インデックス

<ul> 
    <?php foreach ($this->customeObject as $obj_cus) : ?> 
     <li>ID: <?php echo $obj_cus->id?>| Artist: <?php echo $obj_cus->artist?> | Name:<?php echo $obj_cus->name?> | Sem:<?php echo $obj_cus->sem?> | Age:<?php echo $obj_cus->age?></li> 
    <?php endforeach; ?> 
    </ul> 

を.phtmlが、それは誤り下に示します210 enter image description here

答えて

1
$select = new Select(); 
$select->from(array('s' => 'stud')); 
/* Select columns from primary table without prefix table */ 
$select->columns(array('id', 'name', 'sem', 'age')); 

/* If need where */ 
$select->where(array('s.id' => 14)); 

/* It's a INNER JOIN */ 
$select->join(
    array('a' => 'album'), 
    'a.id = s.album_id', 
    /* Select joined columns */ 
    array('artist') 
); 
$select->order('s.id DESC'); 
$select->limit(5); 
return $resultSet = $this->tableGateway->selectWith($select); 
1

列メソッドのシグネチャは次のようになります。prefixColumnsWithTableが有効になっているデフォルトでそう

public function columns(array $columns, $prefixColumnsWithTable = true) 

不明列

だからこの問題を解決する最も簡単な方法は、列の2番目のパラメータとしてfalseを渡すことですSSID:

エラーメッセージを取得している理由です

$select->columns(array('s.id','a.artist', 's.name', 's.sem','s.age'), false); 
関連する問題