所以我有一个getResources调用,通过这个调用给我一个整数值:
[[!getResources? &parents=`[[*id]]` &totalVar=`totalLinks`]]
输出到[[+ totalLinks]]并使用它输入到我的代码段
[[!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;
我的问题是如何将这些2粘在一起所以我只需要调用我的代码片段?
答案 0 :(得分:2)
完全摆脱getResources调用,在你的代码片段中使用:getChildIds:
类似的东西:
<?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];
因此,根据您的应用,您可能需要查看其他问题:
[提示:你可以google&#34; php将数字转换为它的字符串名称&#34;并提出几个选项]