4

I am working on Magento 2.0.4 . I need to get collection of my custom table. For this I created the function getAreaCollection() in my block file but I got following error when I add constructor in block file.

Object DOMDocument should be created.

Here is my block file (\app\code\Techno\Area\Block\Area\index.php):-

namespace Techno\Area\Block\Area;

use Techno\Area\Block\BaseBlock;
use Techno\Area\Model\Area as AreaModel;
use Techno\Area\Model\Status;

class Index extends BaseBlock {

    protected $_areaFactory;
    protected $_area;
    protected $_areaCollectionFactory;
    protected $_areaHelper;

    public function __construct(
        Magento\Framework\View\Element\Template\Context $context 
        Techno\Area\Model\ResourceModel\Area\CollectionFactory $areaCollectionFactory, 
        Techno\Area\Model\AreaFactory $areaFactory, 
        AreaModel $area,
        Techno\Area\Helper\Data $areaHelper    
    ) {
        parent::__construct($context);
        $this->_areaFactory = $areaFactory;
        $this->_area = $area;
        $this->_areaCollectionFactory = $areaCollectionFactory;
        $this->_areaHelper = $areaHelper;
    }


    public function getAreaCollection() {
        $areaCollection = $this->_areaCollectionFactory->create()
                ->addFieldToFilter('status', Status::STATUS_ENABLED)
                ->setOrder('area_name', 'ASC');

        return $areaCollection;
    }

}

Can anyone guide me to make this working ?

1 Answer 1

4

I got the solution:

I was using

Magento\Framework\View\Element\Template\Context $context 

in Techno\Area\Block\Area constructor and this was already written in my block custom base class Techno\Area\Block\BaseBlock;

SO I changed this to

\Techno\Area\Block\Context $context,

and it is working for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.