Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Phalcon4 Volt service error - cant set

Hello,

I try to migrate old project to Phalcon4, but i am stuck at volt service. Here is my code in Module.php:


        $di->set('view', function () use ($config) {
            $view = new View();
            $view->setViewsDir($config->modules->{$config->module}->dir.'views/');
            $view->setLayoutsDir('_layouts/');

            $view->registerEngines([
                '.volt' => 'voltService'
            ]);

            $view->registerEngines([
                '.volt' => function (\Phalcon\Mvc\ViewBaseInterface $view, \Phalcon\Di\DiInterface $di) use ($config, $folder) {
                    $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);

                    $volt->setOptions([
                        'always' => $config->development,
                        'path' => $config->dirs->cache . 'volt/',
                        'separator' => '_'
                    ]);

                    // Custom filters
                    $compiler = $volt->getCompiler();
                    return $volt;
                }
            ]);

            return $view;
        }, true);

And the error is:

Fatal error: Uncaught ArgumentCountError: Too few arguments to function Modules\Admin\Module::Modules\Admin\{closure}(), 1 passed and exactly 2 expected in D:\www\drooble.v3-back\modules\admin\Module.php on line 60

The line 60 is where '.volt' located- so for some reason, second parametter is missing or something. If i remove \Phalcon\Di\DiInterface $difrom the function - volt was started, but give me error about session (it is not accessible).

Some ideas?

edited 20d ago

The issue is function (\Phalcon\Mvc\ViewBaseInterface $view, \Phalcon\Di\DiInterface $di) here- that second parameter. Not the $folder.

Thank u anyway

I think you can remove the 2nd parameter $folder and have a look at https://github.com/phalcon/vokuro/blob/dbe10f654b53457cdcc37a67dea9d7d6f29edcdc/src/Providers/ViewProvider.php#L31

But... u make me think about... i will try something. Thanks.



7.9k
Accepted
answer
edited 20d ago

Something like this should work (didn't try)

$di->set('view', function () use ($config, $di) {
            $view = new View();
            $view->setViewsDir($config->modules->{$config->module}->dir.'views/');
            $view->setLayoutsDir('_layouts/');

            $view->registerEngines([
                '.volt' => function (\Phalcon\Mvc\View $view) use ($config, $di) {
                    $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);

                    $volt->setOptions([
                        'always' => $config->development,
                        'path' => $config->dirs->cache . 'volt/',
                        'separator' => '_'
                    ]);

                    // Custom filters
                    $compiler = $volt->getCompiler();
                    return $volt;
                }
            ]);

            return $view;
        }, true);

Yes, i make the same way and its working. Thank u for idea and support.

Now other stuff are broken... for example dispatcher didnt give me -getControllerName sometimes... and... i give up.

Will wait final version :/

Something like this should work (didn't try)

$di->set('view', function () use ($config, $di) {
           $view = new View();
           $view->setViewsDir($config->modules->{$config->module}->dir.'views/');
           $view->setLayoutsDir('_layouts/');

           $view->registerEngines([
               '.volt' => function (\Phalcon\Mvc\View $view) use ($config, $di) {
                   $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);

                   $volt->setOptions([
                       'always' => $config->development,
                       'path' => $config->dirs->cache . 'volt/',
                       'separator' => '_'
                   ]);

                   // Custom filters
                   $compiler = $volt->getCompiler();
                   return $volt;
               }
           ]);

           return $view;
       }, true);


7.9k

Have a look a the change log https://docs.phalcon.io/4.0/en/upgrade for all required changes. A lot has changed. Not aware of any dispatcher issues at the moment. Please feel free to open an issue at github if you spotted one.

Ye, mate :) I am on that page from a day... API tab and documentation. But still... i dont know... About dispatcher- i switch to v3 for today couse ot work... and tomorrow will try continue refactor for v4. Will open issue for sure.

Thank again!

Have a look a the change log https://docs.phalcon.io/4.0/en/upgrade for all required changes. A lot has changed. Not aware of any dispatcher issues at the moment. Please feel free to open an issue at github if you spotted one.