Commit 80178e6d by Alexei Tenitski Committed by Alexander Makarov

Fix for #2925 and #4290 (Twig does not properly support null attribute and relationship values)

parent 071105e9
...@@ -54,6 +54,11 @@ class Extension extends \Twig_Extension ...@@ -54,6 +54,11 @@ class Extension extends \Twig_Extension
]; ];
} }
public function initRuntime(\Twig_Environment $environment)
{
$environment->setBaseTemplateClass('yii\twig\Template');
}
/** /**
* @inheritdoc * @inheritdoc
*/ */
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\twig;
/**
* Template base class
*
* @author Alexei Tenitski <alexei@ten.net.nz>
*/
abstract class Template extends \Twig_Template
{
protected function getAttribute($object, $item, array $arguments = array(), $type = \Twig_Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
{
// 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;
}
return parent::getAttribute($object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment