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

view not rendering in production environment

Hi, I am using vokuro for a project. I created a new controller, its view for an action and the form to be used in that view.

Everything is working in my local environment, however when transferred to web server, the new controller results in empty i.e. only the view from that action is not showing.

During investigation, I found that the cache file for that view is also not being generated.

What should I do?



85.5k

probably permisions for volt folder.

chmod 775 voltCacheFolder

if you are not familiar with permissions, please read about it what 1st,2nd and 3rd number stands for, and try not to 777 everything, please.

Thanks Izo for your input but as I said cache is being populated by other views but only this view is not being generated.



85.5k

dispaly errors , enable error reporting etc. for that php ?



13.8k
edited Aug '17

Can you temporary change the code for the view component in app/config/services.php to


$di->setShared('view', function () {
    $config = $this->getConfig();

    $view = new View();
    $view->setDI($this);
    $view->setViewsDir($config->application->viewsDir);

    $view->registerEngines([
        '.volt' => function ($view) {
            $config = $this->getConfig();

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

            if($config->settings->development === false) {
                $volt->setOptions([
                    'compiledPath' => $config->application->cacheDir,
                    'compiledSeparator' => '_',
                    'compileAlways' => TRUE // use if problems with updating files exist
                ]);

                // Alternative to force clear cache and re-compile files
                // array_map('unlink', glob($config->application->cacheDir . 'volt/*.php'));
                // $volt->setOptions(array(
                //     'compileAlways' => TRUE,
                // ));

            }

            // Custom volt functions
            $compiler = $volt->getCompiler();
            $compiler->addFunction('split', 'explode');

            return $volt;
        },
        '.phtml' => PhpEngine::class // php >= 5.5 only
        //'.phtml' => 'Phalcon\Mvc\View\Engine\Php' // php <= php 5.4 work-around

    ]);

    return $view;
});

And the load the page and see if it works?

Can you temporary change the code for the view component in app/config/services.php to


$di->setShared('view', function () {
   $config = $this->getConfig();

   $view = new View();
   $view->setDI($this);
   $view->setViewsDir($config->application->viewsDir);

   $view->registerEngines([
       '.volt' => function ($view) {
           $config = $this->getConfig();

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

           if($config->settings->development === false) {
               $volt->setOptions([
                   'compiledPath' => $config->application->cacheDir,
                   'compiledSeparator' => '_',
                   'compileAlways' => TRUE // use if problems with updating files exist
               ]);

               // Alternative to force clear cache and re-compile files
               // array_map('unlink', glob($config->application->cacheDir . 'volt/*.php'));
               // $volt->setOptions(array(
               //     'compileAlways' => TRUE,
               // ));

           }

           // Custom volt functions
           $compiler = $volt->getCompiler();
           $compiler->addFunction('split', 'explode');

           return $volt;
       },
       '.phtml' => PhpEngine::class // php >= 5.5 only
       //'.phtml' => 'Phalcon\Mvc\View\Engine\Php' // php <= php 5.4 work-around

   ]);

   return $view;
});

And the load the page and see if it works?

So i just added ". 'volt/'" in 'compiledPath' => $config->application->cacheDir

Rest used your code and following error was being shown:

Volt directory can't be written

0 [internal function]: Phalcon\Mvc\View\Engine\Volt\Compiler->compileFile('/home/onecard/d...', '/home/onecard/d...', false)

1 [internal function]: Phalcon\Mvc\View\Engine\Volt\Compiler->compile('/home/onecard/d...')

2 [internal function]: Phalcon\Mvc\View\Engine\Volt->render('/home/onecard/d...', Array, true)

3 [internal function]: Phalcon\Mvc\View->_engineRender(Array, 'index/index', true, true, NULL)

4 [internal function]: Phalcon\Mvc\View->render('index', 'index', Array)

5 /home/onecard/domains/app.onecard.pk/public_html/public/index.php(41): Phalcon\Mvc\Application->handle()

6 {main}

and nothing is being shown now on any link.

Question is how to resolve it as the permissions on the folder are shown in the picture.

Permissions Screenshot



13.8k
edited Aug '17

If you echo/dump the compiled path. How does it look like?

for example


echo $config->application->cacheDir;
exit;

Ofcourse if I understand correct with the volt part you concatinated.

/home/xxxx/domains/app.xxxx/public_html/cache/

If you echo/dump the compiled path. How does it look like?

for example


echo $config->application->cacheDir;
exit;

Ofcourse if I understand correct with the volt part you concatinated.



13.8k
edited Aug '17

But what about this part: "So i just added ". 'volt/'" in" You concatinated a directory with the name 'volt' from what I understood. I'm trying to figure out if the map 'volt' exists in the cache dir or if permissions are set recursivly on it and/or if the path with 'volt' concatinated doesnt look like, /home/xxxx/domains/app.xxxx/public_html/cachevolt.

Regarding Permissions, i tried setting 777 to cache folder recursively but no gain. Regarding concatination, it looks like /home/xxxx/domains/app.xxxx/public_html/cache/volt

Now the weird part is that for every other view, the cache/volt gets the compiled view as expected but only one controller's view is not getting populated. Very weird.

But what about this part: "So i just added ". 'volt/'" in" You concatinated a directory with the name 'volt' from what I understood. I'm trying to figure out if the map 'volt' exists in the cache dir or if permissions are set recursivly on it and/or if the path with 'volt' concatinated doesnt look like, /home/xxxx/domains/app.xxxx/public_html/cachevolt.



13.8k
edited Aug '17

Can you post the controller and the view file



5.9k
Accepted
answer

It turned out to be the view file name issue. I used camel case in controller's action and did not follow the same in view.

Also, the development environment was windows, which is not normally case sensitive and the production environment is ubuntu, a case sensitive environment.

Anyways thanks Videles and Izo.