如何获得正常格式的cakephp查询结果?

问题描述:

我有这样的查询$ this-> find('all',$ query);。如何获得这个查询的结果数组就像在普通的PHP?如何获得正常格式的cakephp查询结果?

+1

我强烈建议您学习如何处理CakePHP为它们提供的格式的结果 - 从长远来看,它会让事情变得更容易。 – JJJ 2012-07-27 15:24:11

+0

你能否详细说明一下? – tyjkenn 2012-07-27 20:20:45

$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; 
     }