We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

(int) return 0 in addFilter

Hello!

I'm trying to write a custom filter.

$volt
->getCompiler()
->addFilter(
'num2str', 
function($resolvedArgs, $exprArgs){
$number = (int) $resolvedArgs;
return '"' . $number . '"';
 }
);

call filter:

{{contract.repaymentPeriod|num2str}}

$resolvedArgs is in string with the value '18'. but my filter returns 0.

tell me how to convert the left argument to a number?

$resolvedArgs is an array, try:


function($resolvedArgs, $exprArgs){
$number = (int) $resolvedArgs[0];
return '"' . $number . '"';
 }


4.3k

$resolvedArgs is an array, try:


function($resolvedArgs, $exprArgs){
$number = (int) $resolvedArgs[0];
return '"' . $number . '"';
}

filters $resolveArgs is a string. I solved this problem by writing a separate class for the filter.