I want to get the collection's count by using this method :

public function getCount()
        $connection = $this->getConnection();
        $select = $connection->select();
        $select->from($this->getEntityTable(), 'COUNT(*)');
        $result = (int)$connection->fetchOne($select);
        return $result;

in the file Vendor\Module\Model\ResourceModel\Item\Collection.php

I have the following error :

Fatal error: Uncaught Error: Call to undefined method Vendor\Module\Model\ResourceModel\Item\Collection::getEntityTable() in C:\xampp\htdocs\magento2\app\code\Vendor\Module\Model\ResourceModel\Item\Collection.php:31 Stack trace: #0 C:\xampp\htdocs\magento2\app\code\Vendor\Module\Block\Crud.php(43)

Am I missing something in the constructor ?


1 Answer 1


I solved the problem, I should call getMainTable() and not getEntityTable().

Your Answer

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

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