Search code examples
dynamicphalconvolt

PhalconPHP, volt and custom function: way to call dynamic function


Here is my code

/**
 * Setting up the view component
 */
     $di->setShared('view', function () use ($config) {

    $view = new View();

    $view->setViewsDir($config->application->viewsDir);

    $view->registerEngines(array(
        '.volt' => function ($view, $di) use ($config) {

            $volt = new VoltEngine($view, $di);

            $volt->setOptions(array(
                'compiledPath' => $config->application->cacheDir,
                'compiledSeparator' => '_'
            ));

            $volt->getCompiler()->addFunction(
                'paymentStatus',
                function($key)
                {
                    return @"Info::paymentStatus({$key})";
                }
            );

            return $volt;
        },
        '.phtml' => 'Phalcon\Mvc\View\Engine\Php'
    ));

    return $view;
});

And the error message (expected to be honest to say)

Strict Standards: Non-static method Info::paymentStatus() should not be called statically, assuming $this from incompatible context in /home/zxcvbnm/public_html/app/cache/_home_zxcvbnm_public_html_app_views_invoice_admininvoice.volt.php on line 49

How can I call method dynamically?


Solution

  • If you want to call your method is statically, you must change the method implementation to static:

    public static function paymentStatus($key){
         ...code
    }