2012-07-27 42 views
1

我有這樣的查詢$ this-> find('all',$ query);。如何獲得這個查詢的結果數組就像在普通的PHP?如何獲得正常格式的cakephp查詢結果?

+1

我強烈建議您學習如何處理CakePHP爲它們提供的格式的結果 - 從長遠來看,它會讓事情變得更容易。 – JJJ 2012-07-27 15:24:11

+0

你能否詳細說明一下? – tyjkenn 2012-07-27 20:20:45

回答

0
$this->getResultInNormalFormat($this->find('all',$query),array('alias1','alias2','alias2'));  
    function getResultInNormalFormat($query_result,$tables){ 
     $extracted_array = array(); 
     $i = TRUE; 
     foreach($tables as $table){ 
      $extracted_arrays[] =Set::extract($query_result,'{n}.'.$table) ; 
      } 
     foreach($extracted_arrays as $extracted_array){ 
      if($i){ 
       $merged_array = (Set::merge($extracted_array)); 
      } 
      else{ 
       $merged_array = (Set::merge($extracted_array,$merged_array)); 
      } 
      $i = FALSE; 
      } 
     return $merged_array; 
     }