Volt engine does not work in phalcon

WBOY
Release: 2016-08-25 10:37:13
Original
1469 people have browsed it

In the generated multi-module project, the volt engine does not work, js and css loading does not respond, partials does not work, and the view cannot be output. It seems that the volt engine has not been registered successfully or is it due to other reasons?

ps: But it comes with its own engine. Files in the format with the suffix .phtml can import js, css, and partials files according to the manual. Based on the above, after changing the suffix to .volt format, what else needs to be changed to make it work?

Directory structure

Volt engine does not work in phalcon

The following is part of the code in config/services.php, which is automatically generated when generating the project

<code>$di->setShared('view', function () use ($config) {

    $view = new View();

    $view->setViewsDir($config->application->viewsDir);

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

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

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

            return $volt;
        },
        '.phtml' => 'Phalcon\Mvc\View\Engine\Php'
       // '.volt' => 'Phalcon\Mvc\View\Engine\Php'
    ));

    return $view;
});</code>
Copy after login
Copy after login
Copy after login

Module.php under the module is still the same as when the project was generated and has not changed!

in views/index.volt

Loading partials

<code>{{ partial("partials/header") }}
{{ partial("partials/main") }}
{{ partial("partials/footer") }}</code>
Copy after login
Copy after login
Copy after login

Load js

<code>{{ javascript_include("/js/1.11.3.jquery.min.js") }}</code>
Copy after login
Copy after login
Copy after login

Reply content:

In the generated multi-module project, the volt engine does not work, js and css loading does not respond, partials does not work, and the view cannot be output. It seems that the volt engine has not been registered successfully or is it due to other reasons?

ps: But it comes with its own engine. Files in the format with the suffix .phtml can import js, css, and partials files according to the manual. Based on the above, after changing the suffix to .volt format, what else needs to be changed to make it work?

Directory structure

Volt engine does not work in phalcon

The following is part of the code in config/services.php, which is automatically generated when generating the project

<code>$di->setShared('view', function () use ($config) {

    $view = new View();

    $view->setViewsDir($config->application->viewsDir);

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

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

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

            return $volt;
        },
        '.phtml' => 'Phalcon\Mvc\View\Engine\Php'
       // '.volt' => 'Phalcon\Mvc\View\Engine\Php'
    ));

    return $view;
});</code>
Copy after login
Copy after login
Copy after login

Module.php under the module is still the same as when the project was generated and has not changed!

in views/index.volt

Loading partials

<code>{{ partial("partials/header") }}
{{ partial("partials/main") }}
{{ partial("partials/footer") }}</code>
Copy after login
Copy after login
Copy after login

Load js

<code>{{ javascript_include("/js/1.11.3.jquery.min.js") }}</code>
Copy after login
Copy after login
Copy after login

Post the code part for registering your volt template in DI
Post the code part for loading JS and CSS
Post the code part for using partial
Post the code! Post the code! Post the code! Let’s talk about three again! Raising code-related questions without posting the code is a hooligan

<code>$di->set('view', function () use ($config) {
    $view = new View();
    $view->setViewsDir(APP_PATH . $config->application->layouts_dir);
    $view->registerEngines(
        array(
            '.volt'  => function ($view, $di) use ($config) {
                $volt = new VoltExtension($view, $di);
                $volt->setOptions(
                    array(
                        'compiledPath'      => APP_PATH . $config->application->cache_dir,
                        'compileAlways'     => $config->application->debug,
                        'compiledSeparator' => '_',
                        'layoutDir'         => $config->application->layouts_dir,
                    ));
                if (!empty($config->volt->extensions)) {
                    foreach ($config->volt->extensions as $extension_class_name) {
                        $di->get('volt.extension')->register($volt, new $extension_class_name($di));
                    }
                }
                return $volt;
            },
            '.phtml' => 'Phalcon\Mvc\View\Engine\Php'
            ......
        ));
    return $view;
}, true);</code>
Copy after login

Directory structure

Volt engine does not work in phalcon

The following is part of the code in config/services.php, which is automatically generated when generating the project

<code>$di->setShared('view', function () use ($config) {

    $view = new View();

    $view->setViewsDir($config->application->viewsDir);

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

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

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

            return $volt;
        },
        '.phtml' => 'Phalcon\Mvc\View\Engine\Php'
       // '.volt' => 'Phalcon\Mvc\View\Engine\Php'
    ));

    return $view;
});</code>
Copy after login
Copy after login
Copy after login

Module.php under the module is still the same as when the project was generated and has not changed!

in views/index.volt

Loading partials

<code>{{ partial("partials/header") }}
{{ partial("partials/main") }}
{{ partial("partials/footer") }}</code>
Copy after login
Copy after login
Copy after login

Load js

<code>{{ javascript_include("/js/1.11.3.jquery.min.js") }}</code>
Copy after login
Copy after login
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!