最近我们公司要开发一套API。代码定为PHP。框架不定。因我是主程并且对Yii比较熟悉。所以准备选用YII做为此套API的框架。不知道YII做API框架的性能怎样?
另外写了个AR转array的函数。请大神看一下还有什么地方可以优化的?
/**
* @param $value
* @param array $relation
* @return array
* $value AR对象,$relation relation名称
* 将AR对象转成Array对象.
*/
public static function convertModel($value,$relation=array()){
if(count($value)>0&&is_array($value)){
$index=0;
foreach($value as $model){
$list[$index]=$model->attributes;
foreach($relation as $relationValue){
if(is_array($relationValue)){
foreach($relationValue as $key=>$value){
$list[$index][$key]=self::convertModel($model[$key],array($value));
}
}else{
if(count($model[$relationValue]->attributes)>0){
$list[$index][$relationValue]=$model[$relationValue]->attributes;
}else{
$list[$index][$relationValue]=self::convertModel($model[$relationValue]);
}
}
}
$index++;
}
return $list;
}else{
return $value->attributes;
}
}