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

Problem with Volt compiling

Hi there,

I'm getting the following error message:

Phalcon\Mvc\View\Exception: Volt directory can't be written in /mae/www/html/host_ui/public/index.php on line 98

Call Stack: 0.0216 672008 1. {main}() /mae/www/html/host_ui/public/index.php:0 6.3427 699448 2. Phalcon\Mvc\Application->handle() /mae/www/html/host_ui/public/index.php:98

I have this code:

    //Setup the view component
    $di->set('view', function() use ($config) {
        $view = new \Phalcon\Mvc\View();
        $view->setViewsDir(__DIR__ . $config->application->viewsDir);
        $view->registerEngines(array(
            '.volt' => 'volt',
            '.phtml' => 'Phalcon\Mvc\View\Engine\Php'
        ));
        return $view;
    });

    $di->set('volt', function($view, $di) use ($config) {
        $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
        $volt->setOptions(array(
            'compiledPath' => $config->application->cacheDir
        ));
        return $volt;
    }, true);

My cacheDir and all of its subdirectories have been set to 777.

Is there anything else that might be going wrong here? Do I need to set rights on any other folder for Volt to work?

Thanks.



51.2k

What is the output of $config->application->cacheDir ? In your cache directory, be sure that you have a directory called "volt"



38.8k

Hi, my cacheDir value is /../cache/volt/ and I have a 'cache' directory (at the same level as app and public) that contains a 'volt' directory. I set 777 to everything.



51.2k
Accepted
answer

For sure there is a mistake with the path. Can you try this ?

    $di->set('volt', function($view, $di) use ($config) {
        if (!is_dir($config->application->cacheDir)) {
            mkdir($config->application->cacheDir);
        }   

        $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
        $volt->setOptions(array(
            'compiledPath' => $config->application->cacheDir
        ));
        return $volt;
    }, true);


38.8k

OK, now we're getting somewhere! :)

Here is my config.ini file:

[application]
controllersDir = /../app/controllers/
modelsDir      = /../app/models/
viewsDir       = /../app/views/
pluginsDir     = /../app/plugins/
libraryDir     = /../app/library/
cacheDir       = /../cache/volt/
baseUri        = /host_ui/

If I change

cacheDir       = /../cache/volt/

to

cacheDir       = ../cache/volt/

It works? It is now targetting my existing folder whereas before with your additional test, it couldn't find the directory? As far as I can see, it should have worked without changing the cacheDir path. All of the other xxxxDir paths work fine with the leading (and trailing) '/'.

I'm confused?



51.2k
edited Apr '14

Are you developing on windows ? Also, in my opinion, (not related to your problem) using INI files is not ok at all. Yes, it's fast to load them, but this is it. I would switch to plain php (you will be able to use constants like " DIR " , DIRECTORY_SEPPARATOR, etc) or YAML.



38.8k

Nope I'm developing on Mac and uploading to/running from CentOS. As far as the .ini file approach goes, from the Documentation INVO tutorial, it seems to suggest that using an .ini files is the recommended approach. That's the only reason I used the .ini file! :)

I'll take your advice around this. I did it all the way you suggested in the first place and only recently swapped to using the .ini file.

Thanks very much for your help.

edited Dec '16

I usually use a constant ROOT_PATH which points to my top level folder of the application.

Then my configuration (php array) becomes something like this:

return [
    'controllersDir' = ROOT_PATH . '/app/controllers/',
    'modelsDir'      = ROOT_PATH . '/app/models/',
    'viewsDir'       = ROOT_PATH . '/app/views/',
    'pluginsDir'     = ROOT_PATH . '/app/plugins/',
    'libraryDir'     = ROOT_PATH . '/app/library/',
    'cacheDir'       = ROOT_PATH . '/cache/volt/',
    'baseUri'         = '/host_ui/',
];