寻呼机不显示项目。它确实显示了它们的数量,甚至是分页。但这没什么意义。
代码在下面。
Block / TestClass.php
<?php
namespace Wade\Crud\Block;
class TestClass extends \Magento\Framework\View\Element\Template{
/**public function _prepareLayout()
{
return parent::_prepareLayout();
}*/
protected $_pageFactory;
protected $_postFactory;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\View\Result\PageFactory $pageFactory,
\Wade\Crud\Model\PostFactory $postFactory
) {
$this->_pageFactory = $pageFactory;
$this->_postFactory = $postFactory;
return parent::__construct($context);
}
protected function _prepareLayout(){
parent::_prepareLayout();
if ($this->getModelData()) {
$pager = $this->getLayout()->createBlock('Magento\Theme\Block\Html\Pager')
->setAvailableLimit(array(5=>5))->setShowPerPage(true)->setCollection($this->getModelData());
$this->setChild('pager', $pager);
$this->getModelData()->load();
}
return $this;
}
public function getPagerHtml(){
return $this->getChildHtml('pager');
}
public function getModelData(){
$this->_isScopePrivate = true;
$data = $this->_postFactory->create();
$collection = $data->getCollection();
return $collection;
}
}
?>
.phtml模板文件
<?php if ($block->getPagerHtml()): ?>
<div class="order-products-toolbar toolbar bottom"><?php echo $block->getPagerHtml(); ?></div>
<?php endif ?>
输出显示: 第1项到第5项,共14项。因此,至少显示了正确数量的项目。但同样,没有显示任何项目。