Php Magento“$这->;loadLayout()”;在AJAX中需要很长时间

Php Magento“$这->;loadLayout()”;在AJAX中需要很长时间,php,magento,Php,Magento,我是magento的新手&我想在我的新站点中添加“AJAX购物车”功能。然后,我遵循了本教程的步骤。 但我注意到,作出回应需要很长时间。原因是“$this->loadLayout()”在下面的代码中占用了很长时间 $this->loadLayout(); $sidebar = $this->getLayout()->getBlock('cart_sidebar')->toHtml(); 在谷歌呆了一段时间后,我将代码改为fallowing $sidebar = $th

我是magento的新手&我想在我的新站点中添加“AJAX购物车”功能。然后,我遵循了本教程的步骤。

但我注意到,作出回应需要很长时间。原因是“$this->loadLayout()”在下面的代码中占用了很长时间

$this->loadLayout();
$sidebar = $this->getLayout()->getBlock('cart_sidebar')->toHtml();
在谷歌呆了一段时间后,我将代码改为fallowing

$sidebar = $this->getLayout()->createBlock('checkout/cart_sidebar')->setTemplate('path_my _template.phtml')->toHtml();
然后时间从20秒缩短到5秒。除了url之外,两个代码中的输出都是相同的。我正在打印(回显)模板中的“签出URL”。在第一个代码中,URL以“”结尾,但在第二个代码中没有


有人知道为什么会这样吗?我想减少项目添加时间和获取安全URL的时间

我通过将代码更改为fallows解决了这个问题

$this->getLayout()->createBlock('page/html');
$sidebar = $this->getLayout()->createBlock('checkout/cart_sidebar')->setTemplate('path_my _template.phtml')->toHtml();