2012-03-11 13 views
1

私のCodeIgniterモデルメソッドは、すべての「ケース」を特定のサブカテゴリで取得します。次に、それらを適切な "get_case"結果を持つ新しい配列に変換すると仮定しますが、同じ配列要素を返し続けます。私が関連するすべての関連メソッドは、それ自身で正しく機能しているようですが、この関数では同じ結果が繰り返されます。ここCodeIgniterモデル配列が期待どおりにプッシュされない

は、私はとのトラブルを抱えています方法/機能は、それがここに簡単な

function get_subcategories_cases($subcategory) 
    { 
    $this->db->order_by('sortorder','asc'); 
    $this->db->where('subcategoryid', $subcategory); 
    $query = $this->db->get('cases'); 
    $query = $query->result(); 
    // 
    $outputArray = array(); 
    foreach ($query as $item) { 
    array_push($outputArray, $this->get_case($item->id)); 
    } 
    return $outputArray; 
    } 

する必要がありますようにこれはそう...あなたは結果を保存している場合get_case方法は

function get_case($id) 
{ 
//print_r($id); 
$this->db->where('id', $id); 
$this->db->limit(1); 
$query = $this->db->get('cases'); 
$query = $query->row(); 
// 
$this->id    = $query->id; 
$this->sortoder   = $query->sortorder; 
$this->surgeonid  = $query->surgeonid; 
$this->subcategoryid = $query->subcategoryid; 
$this->age    = $query->age; 
$this->gender   = $query->gender; 
$this->typeofsurgery = $query->typeofsurgery; 
$this->isactive = $query->isactive; 
$this->isfeatured  = $query->isfeatured; 
$this->iswarning  = $query->iswarning; 
$this->metatitle  = $query->metatitle; 
$this->metadescription = $query->metadescription; 
$this->metakeywords  = $query->metakeywords; 
$this->casedescription = $query->casedescription; 
$this->photos  = $this->insert_case_photos($query->photos); 
// 
return $this; 
} 

答えて

2

されていますget_case()$thisでは、get_case()メソッド以外のスコープを持つモデル(オブジェクト)属性にそれらを保存するので、それはおそらく何かと関係します。

は、ローカル変数にクエリ結果を保存してください:

function get_case($id) 
{ 
    //print_r($id); 
    $this->db->where('id', $id); 
    $this->db->limit(1); 
    $query = $this->db->get('cases'); 
    $case = $query->row(); 
    // 
    $case->photos = $case->insert_case_photos($case->photos); 
    // 
    return $case; 
} 
+0

それは、素晴らしいことだおかげ – jnollette

+0

だったこと - それは助け嬉しいです。あなたが応答に満足していれば、受け入れられた答えとしてそれをマーキングしてもよろしいですか?それはSOを整理して維持するのに役立ち、その代わりに我々は両方ともより良い評判を得る:) –

関連する問題