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

Phalcon\Mvc\View: sometimes getRender returns empty string with the same params

I wrote the following peice of code to localize the problem. It executes getRender 100 times and groups result string length. output examples: Array ( [510] => 100 ) Array ( [510] => 93 [0] => 7 ) Array ( [510] => 99 [0] => 1 ) Array ( [510] => 87 [0] => 13 ) ... etc

so, sometimes getRender returns empty string with the same params

    $vars = array(
        'title' => 'title1',
        'html' => '<div>test</div>',
        'id' => 'video0',
        'first' => 1,
    );
    $view = $this->getDI()->get('view');
    $variants = [];
    for ($i=0; $i < 100; $i++)
    { 
        $view->setVars($vars);
        $html =  $view->getRender('article', 'video', $vars);
        $idx = mb_strlen( $html );
        if ( !isset($variants[$idx]) )
        {
            $variants[$idx] = 1;
        } else {
            $variants[$idx] = $variants[$idx] + 1;
        };
    };
    print_r($variants);

view service initialization:

    $view = new \Phalcon\Mvc\View();

    $config = $di->get('config');
    $view->setViewsDir($config->application->viewsDir);

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

            $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);

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

            \fx\view\FunctionsRegistrar::register($volt->getCompiler());

            return $volt;
        },
    ));

    return $view;

We tried to change phalcon version from 2.0.13 to latest with no effect.



39.2k
Accepted
answer

Try to stop loop in case of empty result and dump cache file for debug purposes



861
edited Nov '16

Try to stop loop in case of empty result and dump cache file for debug purposes

Thanks for your help, Sergey! The rendered file was empty. I guess that's because of different requests, modifying it concurrently. I turned off "compileAlways" option and now it works.