有时候AJAX返回某个Block类的模板内容需要在controller类中调用getBlock方法
代码如下:
这样不是得不到Block类实例的,必须在调用前执行loadLayout方法:$this->loadLayout();
完整代码为:
代码如下:
$response = $this->getLayout()->getBlock('merchant.review.history')->toHtml();
echo $response;
这样不是得不到Block类实例的,必须在调用前执行loadLayout方法:$this->loadLayout();
完整代码为:
$this->loadLayout();
$response = $this->getLayout()->getBlock('merchant.review.history')->toHtml();
echo $response;
本文介绍了一种在控制器中通过调用 getBlock 方法获取 Block 类实例并将其转换为 HTML 的方法。为了确保正确获取到 Block 实例,需要先执行 loadLayout 方法。
1312

被折叠的 条评论
为什么被折叠?



