문제

추가 중 하나 그리드에 고객의 계정을 받고 컬렉션한다.하지만 내가 원하는 경우 추가 호출기에는 그리드,그 때 나는 오류를 다음과 같:

SQLSTATE[42S22]:열을 발견하지 않:1054Unknown column'main_table.attribute_id'in'field list',쿼리했:SELECT COUNT(DISTINCT main_table.attribute_id)서 custommodule_testmain_table 치(면 콘트롤='2'){"is_exception":false}[]

실제로 없습니다 attribute_id 신청은 거기에서 내 테이블도 나에 대한 필터링을 신청한 이름으로 당신이 있어야 합니다.

십시오:

테스트입니다.phtml

<?php if ($block->getPagerHtml()): ?>
    <div class="order-products-toolbar toolbar bottom"><?php echo $block->getPagerHtml(); ?></div>
<?php endif; ?>

block/test.php

protected function _prepareLayout()
{
    parent::_prepareLayout();
    if ($this->getCollection()) {
        $pager = $this->getLayout()->createBlock(
            'Magento\Theme\Block\Html\Pager',
            'custom.collection.test'
        )->setCollection(
            $this->getCollection()
        );
        $this->setChild('pager', $pager);
        $this->getCollection()->load();
    }
    return $this;
}
public function getPagerHtml()
{
    return $this->getChildHtml('pager');
}

public function getCollection()
{
    if (!$this->getData('collection')) {
        $this->setCollection(
            $this->_objectMangaer->get('Namespace\Modulename\Model\Test')->getCollection()->addFieldToFilter('customer_id',2)
        );
    }
    return $this->getData('collection');
}

참고:면 내가 직접 전화

 $this->getCollection() ;
에서 phtml 파일 내가 가지고 올바른 컬렉션입니다.

도움이 되었습니까?

해결책

을 요구 사항을 충족,우리는 많은 방법을 발견했을위한 최고의 솔루션 매김 Magento2 사용자 정의 컬렉션입니다.여기서 우리는 설명하려고 최선의 방법의 단계를 따르십시오.

참고:가정을 만들었으므로 기본적인 모듈에서 Magento2.여기에 Ipragmatech 은 우리 패키지 Ipreward 은 우리 모듈.십시오 클래스 이름을 변경합니다.

1 단계:컨트롤러를 만듭 라는 Myrewad,작업수(Myreward/Index.php 가)다음 코드를 실행하는 방법

<?php
  namespace Ipragmatech\Ipreward\Controller\Myreward;
  class Index extends \Magento\Framework\App\Action\Action
     {
        public function execute()
           {
               $this->_view->loadLayout();
               $this->_view->renderLayout();
           }
    }

2 단계:블록으로 만들(고 가정하면 당신은 이미 만들기 위한 모델입니다.여기서 우리는 사용자 정의 테이블과 우리가 만들어진 모델로 보상)이름 Reward.php 다음 코드를 추가합니다.이 코드에서는,우리는 추가 페리에 사용자 정의 컬렉션입니다.

<?php
namespace Ipragmatech\Ipreward\Block\Myreward;

use Ipragmatech\Ipreward\Block\BaseBlock;

class Reward extends BaseBlock
  {
/**
 * @var \Ipragmatech\Ipreward\Model\Reward
 */
protected $_rewardCollection;

/**
 * Reward constructor.
 * @param \Magento\Framework\App\Action\Context $context
 * @param \Ipragmatech\Ipreward\Model\Reward $rewardCollection
 */
public function __construct(
    \Ipragmatech\Ipreward\Block\Context $context,
    \Ipragmatech\Ipreward\Model\Reward $rewardCollection,
){
    $this->_rewardCollection = $rewardCollection;
    parent::__construct($context);
}

protected function _prepareLayout()
{

    parent::_prepareLayout();
    $this->pageConfig->getTitle()->set(__('My Reward History'));

    if ($this->getRewardHistory()) {
        $pager = $this->getLayout()->createBlock(
            'Magento\Theme\Block\Html\Pager',
            'reward.history.pager'
        )->setAvailableLimit(array(5=>5,10=>10,15=>15,20=>20))
            ->setShowPerPage(true)->setCollection(
            $this->getRewardHistory()
        );
        $this->setChild('pager', $pager);
        $this->getRewardHistory()->load();
    }
    return $this;
}

public function getPagerHtml()
{
    return $this->getChildHtml('pager');
}
/**
 * function to get rewards point transaction of customer
 *
 * @return reward transaction collection
 */
Public function getRewardHistory()
{
    //get values of current page
    $page=($this->getRequest()->getParam('p'))? $this->getRequest()->getParam('p') : 1;
    //get values of current limit
    $pageSize=($this->getRequest()->getParam('limit'))? $this->getRequest
    ()->getParam('limit') : 5;


    $collection = $this->_rewardCollection->getCollection();
    $collection->setPageSize($pageSize);
    $collection->setCurPage($page);
    $logger->info("Here reward collection: ".$collection->getSelect());
    $logger->info("Here reward collection: Page:".$page." Page size :"
        .$pageSize);
    return $collection;
}

} 3 단계:추가/수정은 다음 코드는 레이아웃 파일 app/code/Ipragmatech/Ipreward/view/frontend/layout/ipreward_myreward_index.xml

  <?xml version="1.0"?>
  <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"               layout="2columns-left" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <update handle="customer_account"/>
      <body>
        <referenceContainer name="content">          
        <block class="Ipragmatech\Ipreward\Block\Myreward\Reward" name="myreward_reward" template="myreward/reward.phtml">
        </block>
       </referenceContainer>      
   </body>
 </page>

4 단계:추가 phtml 파일 앱/드/Ipragmatech/Ipreward/보기/프런트 엔드/templates/myreward/보상입니다.phtml 다음 코드를 추가합니다

enter image description here

그리고 출력은 다음과 같이

enter image description here

때로는 우리가 직면한 어떤 CSS 는 문제 페이지의 제한을 표시되지 않도록 사용하여 다음과 같은 CSS 이 있는 경우 동일한 문제입니다.

 .custom-pager .limiter{
      display: block !important;
  }

희망이 당신에게 많은 도움이 될 것입니다.알려주시기 바랍는 경우에 당신이 어떤 문제에 관한 젠토 사용자 지정입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top