Skip to main content

To get collection you need to do something like this,

=> Block File :

 use [vendor]\[module]\Model\ExtratagsFactory; use Magento\Framework\Data\Collection; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context; class Blockclass extends Template { protected $_modelextratagsFactory; public function __construct(Context $context, ExtratagsFactory $MainmodelextratagsFactory, array $data = []) { $this->_modelextratagsFactory = $MainmodelextratagsFactory; parent::__construct($context, $data); } public function yourfunction() { $MyCollection = $this->__modelextratagsFactory->create() ->getCollection(); return $MyCollection; } } 

This is your BlcokBlock file of your phtml file, and in phtml file you need to call like this,

=> phtml file :

$collection = $block->yourfunction(); 

To get collection you need to do something like this,

 use [vendor]\[module]\Model\ExtratagsFactory; use Magento\Framework\Data\Collection; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context; class Blockclass extends Template { protected $_modelextratagsFactory; public function __construct(Context $context, ExtratagsFactory $MainmodelextratagsFactory, array $data = []) { $this->_modelextratagsFactory = $MainmodelextratagsFactory; parent::__construct($context, $data); } public function yourfunction() { $MyCollection = $this->__modelextratagsFactory->create() ->getCollection(); return $MyCollection; } } 

This is your Blcok file of your phtml file, and in phtml file you need to call like this,

$collection = $block->yourfunction(); 

To get collection you need to do something like this,

=> Block File :

 use [vendor]\[module]\Model\ExtratagsFactory; use Magento\Framework\Data\Collection; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context; class Blockclass extends Template { protected $_modelextratagsFactory; public function __construct(Context $context, ExtratagsFactory $MainmodelextratagsFactory, array $data = []) { $this->_modelextratagsFactory = $MainmodelextratagsFactory; parent::__construct($context, $data); } public function yourfunction() { $MyCollection = $this->__modelextratagsFactory->create() ->getCollection(); return $MyCollection; } } 

This is your Block file of your phtml file, and in phtml file you need to call like this,

=> phtml file :

$collection = $block->yourfunction(); 
added 266 characters in body
Source Link
Dhiren Vasoya
  • 9.7k
  • 14
  • 37
  • 61

To get collection you need to do something like this,

 use [vendor]\[module]\Model\ExtratagsFactory; use Magento\Framework\Data\Collection; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context;     class Blockclass extends Template   {   protected $_modelextratagsFactory;     public function __construct(Context $context,   ExtratagsFactory $MainmodelextratagsFactory,   array $data = [])   {   $this->_modelextratagsFactory = $MainmodelextratagsFactory;     parent::__construct($context, $data);   }     public function yourfunction()   {   $MyCollection = $this->__modelextratagsFactory->create()   ->getCollection();   return $MyCollection;     }   } 

This is your Blcok file of your phtml file, and in phtml file you need to call like this,

$collection = $block->yourfunction(); 

To get collection you need to do something like this,

use [vendor]\[module]\Model\ExtratagsFactory; class Blockclass { protected $_modelextratagsFactory; public function __construct(Context $context, ExtratagsFactory $MainmodelextratagsFactory, array $data = []) { $this->_modelextratagsFactory = $MainmodelextratagsFactory; parent::__construct($context, $data); } public function yourfunction() { $MyCollection = $this->__modelextratagsFactory->create() ->getCollection(); return $MyCollection; } } 

This is your Blcok file of your phtml file, and in phtml file you need to call like this,

$collection = $block->yourfunction(); 

To get collection you need to do something like this,

 use [vendor]\[module]\Model\ExtratagsFactory; use Magento\Framework\Data\Collection; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context;     class Blockclass extends Template   {   protected $_modelextratagsFactory;     public function __construct(Context $context,   ExtratagsFactory $MainmodelextratagsFactory,   array $data = [])   {   $this->_modelextratagsFactory = $MainmodelextratagsFactory;     parent::__construct($context, $data);   }     public function yourfunction()   {   $MyCollection = $this->__modelextratagsFactory->create()   ->getCollection();   return $MyCollection;     }   } 

This is your Blcok file of your phtml file, and in phtml file you need to call like this,

$collection = $block->yourfunction(); 
deleted 1 character in body
Source Link
Dhiren Vasoya
  • 9.7k
  • 14
  • 37
  • 61

To get collection you need to do something like this,

use [vendor]\[module]\Model\ExtratagsFactory; class Blockclass { protected $_modelextratagsFactory; public function __construct(Context $context, ExtratagsFactory $MainmodelextratagsFactory, array $data = []) { $this->_modelextratagsFactory = $MainmodelextratagsFactory; $ parent::__construct($context, $data); } public function yourfunction() { $MyCollection = $this->__modelextratagsFactory->create() ->getCollection(); return $MyCollection; } } 

This is your Blcok file of your phtml file, and in phtml file you need to call like this,

$collection = $block->yourfunction(); 

To get collection you need to do something like this,

use [vendor]\[module]\Model\ExtratagsFactory; class Blockclass { protected $_modelextratagsFactory; public function __construct(Context $context, ExtratagsFactory $MainmodelextratagsFactory, array $data = []) { $this->_modelextratagsFactory = $MainmodelextratagsFactory; $ parent::__construct($context, $data); } public function yourfunction() { $MyCollection = $this->__modelextratagsFactory->create() ->getCollection(); return $MyCollection; } } 

This is your Blcok file of your phtml file, and in phtml file you need to call like this,

$collection = $block->yourfunction(); 

To get collection you need to do something like this,

use [vendor]\[module]\Model\ExtratagsFactory; class Blockclass { protected $_modelextratagsFactory; public function __construct(Context $context, ExtratagsFactory $MainmodelextratagsFactory, array $data = []) { $this->_modelextratagsFactory = $MainmodelextratagsFactory; parent::__construct($context, $data); } public function yourfunction() { $MyCollection = $this->__modelextratagsFactory->create() ->getCollection(); return $MyCollection; } } 

This is your Blcok file of your phtml file, and in phtml file you need to call like this,

$collection = $block->yourfunction(); 
Source Link
Dhiren Vasoya
  • 9.7k
  • 14
  • 37
  • 61
Loading