我在一个小模板中有这些行:
{% for line in order.getItems() %}
{% set os = line.option.getOverstock(true)|first %}
指的是这个方法:
public function getOverstock($getQtyOrdering = false) {
if ($getQtyOrdering === false) {
return $this->overstock;
}
//sort the collection by the quantity field before returning
$iterator = $this->overstock->getIterator();
$iterator->uasort(function ($a, $b) {
return ($a->getQty() < $b->getQty()) ? 1 : -1;
});
$sortResult = new 'Doctrine'Common'Collections'ArrayCollection(iterator_to_array($iterator));
return $sortResult;
}
在我的开发环境中,这是完美的工作,但在现场,参数没有被传递给方法。我已经对照了实时版和开发版,并对照了我们的存储库——一切看起来都很好。
如何调试这种情况?
(我在silex框架中工作)
您可以使用转储函数http://twig.sensiolabs.org/doc/functions/dump.html输出此变量
或添加symfony包symfony/var-dumper
:
composer require symfony/var-dumper
添加转储功能
$app->extend('twig', function ($twig) use ($app, $request) {
$twig->addFunction('dump', new 'Twig_SimpleFunction('dump', ''dump'));
return $twig;
});
并在模板
中输出该变量{% for line in order.getItems() %}
{{ dump(line.option.getOverstock(true)|first) }}
{{ dump(line.option.getOverstock(true)) }}
{{ dump(line) }}
{% set os = line.option.getOverstock(true)|first %}