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

Volt function multiple parameters


I try to add a function to my volt engine with multiple parameters but i have a error, the .php generate have a error :

<?php if (isset($message)) { ?> <?= Volt\FonctionVolt::remplace($message, $polnum, $ident, Array, ) ?> <?php } ?>

Why he add ",Array," ?

My code :

$compiler->addFunction( "remplace", function($message, $polnum, $ident) { return "Volt\FonctionVolt::remplace({$message}, {$polnum}, {$ident})"; }

My fonction :

static function remplace($message, $polnum, $ident) { $template = array('<polnum>', '<ident>'); $replace = array($polnum, $ident); $message = str_replace($template, $replace, $message); return $message; }

And the view : {% if message is defined %} {{remplace(message, polnum, ident)}} {% endif %}

PS : sorry for my bad english, I hope you get what I mean.

PS 2 : When we submit the form without click on the recaptcha, we loose the message. It's normal ?

You have to use on this way

$compiler->addFunction('yourCustomVoltFuntion', function ($arrays, $expression) {
        return 'yourPHPFunction(' . $arrays . ')';

Good luck


Thanks, because of my bad english, i will not understand the parameters. It's working.