2014-09-26 1 views
0

는 SO 난의 GetResources이 호출 날 정수 값을 제공하는 호출 가지고외부 대신 내 스 니펫 안에 getresources 호출로 Modx 스 니펫을 최적화 하시겠습니까?

[[!getResources? &parents=`[[*id]]` &totalVar=`totalLinks`]] 

[+ totalLinks]에 출력하고, I 내 단편에 입력 것을 사용

[[!ChangeNumberToWord? &input=`[[+totalLinks]]`]] 

내 발췌 문장 :

$input = ''; 


function converttoword($total){ 
    if ($total=="1"){ 
     $word = "one"; 
    } elseif($total=="2") { 
     $word = "two"; 
    } elseif($total=="3") { 
     $word = "three"; 
    } elseif($total=="4") { 
     $word = "four"; 
    } elseif($total=="5") { 
     $word = "five"; 
    } elseif($total=="6") { 
     $word= "six"; 
    } elseif($total=="7") { 
     $word ="seven"; 
    } elseif($total=="8") { 
     $word = "eight"; 
    } else{ 
     $word = "$total"; 
    } 
return $word;       
} 

$output = converttoword($input); 

return $output; 

제 질문은이 두 글자를 함께 묶어서 내 발언 코드 만 부를 필요가 있습니까? 당신의 조각에 getChildIds :

http://rtfm.modx.com/revolution/2.x/developing-in-modx/other-development-resources/class-reference/modx/modx.getchildids

뭔가 같은 :

답변

2

사용, 모두 호출의 GetResources 제거하십시오

<?php 
// current resource ID 
$id = $modx->resource->get('id'); 

// get all child ids 
$array_child_ids = $modx->getChildIds($id); 

//so you would count that array 
$num_children = count($array_child_ids); 

// get rid of the ifs to find the word 
$words = array('zero','one','two','three','four','five','six'); 

// do something if no results 
if ($num_children + 1 > count($words)){ 

    return 'out of range'; 

} 

// return the string 
return $words[$num_children]; 

그래서 당신은 당신이 따라 볼 필요가있는 다른 문제가 귀하의 신청서에 :

  • 만약 o 아이들?
  • 리소스 상태 또는 유형 [게시 된 게시판과 게시되지 않은 것, 심볼릭 링크 등]
  • 어린이 수가 3033 [3 천 3 백 33 명] 인 경우 어떻게됩니까?

[힌트 : 당신이 구글 수 있습니다 "PHP는 문자열 이름이다에 숫자를 변환"와 몇 가지 옵션을 마련] 내가 가야 것, 이것에 대한

+0

감사합니다! – TVD

+0

이면 작동으로 표시해야합니다. –