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.

Phalcol 2.0.7 + volt macro = 502

{% macro mymacro() %}
    test
{% endmacro %}
{{ mymacro() }}

This produces 502 error in phalcon 2.0.7. In php-fpm log i see:

[15-Sep-2015 08:59:39] WARNING: [pool www] child 618610 exited on signal 11 (SIGSEGV) after 1.351020 seconds from start
[15-Sep-2015 08:59:39] NOTICE: [pool www] child 618617 started

And that's all, no any other errors. Whats wrong?

PHP 5.5.25



5.4k
edited Sep '15

Isn't it because you should start it using "-" sign: {%- macro not {% and and it the same {%- endmacro ?

No, still 502.

Isn't it because you should start it using "-" sign: {%- macro not {% and and it the same {%- endmacro ?

edited Sep '15

I have the same problem with volt (produce 502 error)

Phalcon 2.0.7 (on Phalcon 2.0.8 the same) php 5.5.12

Any solutions?

I wonder if is it right (source: https://api.phalconphp.com/source/Phalcon/Mvc/View/Engine/Volt.html)

public function callMacro(string! name, array arguments)
{
    var macro;

    if !fetch macro, this->_macros[name] {
        throw new Exception("Macro '" . name . "' does not exist");
    }

    return call_user_func(macro, arguments);
}

It shouldn't be: return calluserfunc(this->_macros[name], arguments); ???



352
Accepted
answer

Temporary solution is override callMacro method.

<?php use Phalcon\Mvc\View\Engine\Volt;

class Volt2 extends Volt {

public function callMacro($name, $arguments)
{

        if (!$this->_macros[$name]){
                throw new Exception("Macro '" . $name . "' does not exist");
        }

        return call_user_func($this->_macros[$name], $arguments);
}

}

And register engine like this

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

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

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

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

Thank you.

Temporary solution is override callMacro method.

<?php use Phalcon\Mvc\View\Engine\Volt;

class Volt2 extends Volt {

public function callMacro($name, $arguments) {

       if (!$this->_macros[$name]){
             throw new Exception("Macro '" . $name . "' does not exist");
     }

     return call_user_func($this->_macros[$name], $arguments);

} }

And register engine like this

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

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

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

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

));



142

Where should I put this code? I mean in which directory

Temporary solution is override callMacro method.

<?php use Phalcon\Mvc\View\Engine\Volt;

class Volt2 extends Volt {

public function callMacro($name, $arguments) {

       if (!$this->_macros[$name]){
             throw new Exception("Macro '" . $name . "' does not exist");
     }

     return call_user_func($this->_macros[$name], $arguments);

} }