Support for method calls on models from Twig templates

This commit is contained in:
Alexei Tenitski
2014-08-07 20:18:15 +12:00
committed by Alexander Makarov
parent 80178e6dee
commit fd5e05b1cf

View File

@ -19,7 +19,11 @@ abstract class Template extends \Twig_Template
// Twig uses isset() to check if attribute exists which does not work when attribute exists but is null
if ($object instanceof \yii\db\BaseActiveRecord) {
return $object->$item;
if ($type == \Twig_Template::METHOD_CALL) {
return $object->$item();
} else {
return $object->$item;
}
}
return parent::getAttribute($object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck);