2016-09-15 2 views
0

phtml 템플릿 파일에 cms 페이지 목록을 가져와야합니다. 코드 아래magento2.1에서 cms 페이지 목록 얻기

$results = Mage::getModel('cms/page')->getCollection() 
    ->addFieldToFilter(array(
     array('field'=> 'title','like' => "%{$search}%"), 
     array('field'=> 'content','like' => "%{$search}%"), 
    )) 
    ->addFieldToFilter('is_searchable', 1); 
  1. 가 magento2.1에서 CMS를 페이지를 얻을하는 방법

  2. 는 CMS를 페이지에 사용자 정의 필드를 추가 할 필요가 젠토의 1.9 버전에서 사용되는 것입니다

답변

0

희망이 도움이 될 것입니다.

클래스 생성자

protected $pageCollectionFactory; 

public function __construct(
    .... 
    \Magento\Cms\Model\ResourceModel\Page\CollectionFactory $pageCollectionFactory, 
    ... 
) { 
    .... 
    $this->pageCollectionFactory = $pageCollectionFactory; 
    .... 
} 

-

namespace Creare\DynamicSitemap\Block; 
class Dynamicsitemap extends \Magento\Framework\View\Element\Template 
{ 
    protected $_storeManager; 

public function __construct(
    \Magento\Backend\Block\Template\Context $context, 
    \Magento\Cms\Model\PageFactory $pageFactory, 
    \Magento\Store\Model\StoreManagerInterface $storeManager,   
    array $data = [] 
) 
{ 
    $this->pageFactory = $pageFactory;   
    $this->_storeManager = $storeManager;   
    parent::__construct($context, $data); 
} 

public function getCreareCMSPages(){ 
    $this->getStoreId(); // current store id 

    $page = $this->pageFactory->create(); 
    foreach($page->getCollection() as $item) 
    { 
     echo "page id : ".$item->getId() . ':: page name title : ' . $item->getTitle().'<br/>'; 
    } 
    die(); 
    $page = $this->pageFactory->create()->load(1); 
    var_dump($page->getData()); 
} 
} 
0

에 추가하기이 그런 다음 당신은 당신의 클래스 메소드 중 하나에이를 사용할 수 있습니다.

$collection = $this->pageCollectionFactory->create(); 
$collection->addFieldToFilter([ 
     ['field'=> 'title','like' => "%{$search}%"], 
     ['field'=> 'content','like' => "%{$search}%", 
    ]) 
    ->addFieldToFilter('is_searchable', 1);