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

When I use phar package my project and some error occur!

engine volt renderlevel View::LEVEL_MAIN_LAYOUT <?php

$ext = ['php', 'volt']; $dir = DIR; $file = "project.phar";

$phar = new Phar(DIR . DIRECTORY_SEPARATOR . $file, FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, $file); $phar->startBuffering();

foreach ($ext as $e) { $phar->buildFromDirectory($dir, '/.' . $e . '$/'); }

$phar->setStub("<?php Phar::mapPhar('{$file}'); require 'phar://{$file}/public/index.php'; __HALT_COMPILER(); ");

$phar->stopBuffering();

echo "Finished {$file}\n";

when I use the project.phar file to server my website. It can render the layout. only render the action view.

if no use phar. It is ok! view code below!

$di->setShared('view', function () { $config = $this->getConfig(); $_manager = new \Phalcon\Events\Manager(); $view = new View(); $view->setDI($this); $_manager->attach('view:beforeRenderView', function ($e, $v, $p) { $logger = $this->getShared('logger'); $logger->debug($p); }); $_manager->attach('view:notFoundView', function ($e, $v, $p) { $logger = $this->getShared('logger'); $logger->debug("not found file is: " . $p); }); //$view->setViewsDir(Phar::running() . "/app/views/"); $view->setEventsManager($manager); $view->setViewsDir($config->application->viewsDir); $view->registerEngines([ '.volt' => function ($view) { $config = $this->getConfig(); $volt = new VoltEngine($view, $this); $volt->setOptions([ 'compiledPath' => '/tmp/cache/', 'compiledSeparator' => '' ]); $compiler = $volt->getCompiler(); $compiler->addExtension(new BuildInFunc());

        $filters = get_class_methods(Helpers::class);
        foreach ($filters as $filter) {
            $compiler->addFilter($filter, Helpers::class . '::' . $filter);
        }

        $func = get_class_methods(Utils::class);
        foreach ($func as $f) {
            $compiler->addFunction($f, Utils::class . '::' . $f);
        }

        return $volt;
    },
    '.phtml' => PhpEngine::class
]);
return $view;

});

$volt->setOptions([ 'compiledPath' => function ($templatePath) { $logger = $this->getShared('logger'); $logger->debug($templatePath); return "/home/sparks/cache/" . md5($templatePath) . ".php"; }, 'compiledSeparator' => '_' ]);

I set the volt compiledPath like this! and it is solve my question!

Thanks phalcon!

please edit your comment so the code looks a little better!