Magento – Magento 2 di:compile command gives fatal error

code generationcommand linemagento2slider

I have taken reference of an old module (Bannerslider) created for Magento 2 Beta version and I am trying to convert it to Magento 2 stable compatible (Mycompany_Bannerslider).

When I enable the module and run the following command it doesn't give errors:

bin/magento setup:upgrade

But when I run bin/magento setup:di:compile command then it shows following error in the terminal:

enter image description here

Below is the model-collection file I am using:

namespace Mycompany\Bannerslider\Model\Resource\Banner;
class Collection extends \Magento\Framework\Model\Resource\Db\Collection\AbstractCollection
{
        public function __construct()
        {
                $this->_init('Mycompany\Bannerslider\Model\Banner', 'Mycompany\Bannerslider\Model\Resource\Banner');
        }
}

Best Answer

Change Resource to ResourceModel

namespace Mycompany\Bannerslider\Model\ResourceModel\Banner;
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
        public function __construct()
        {
                $this->_init('Mycompany\Bannerslider\Model\Banner', 'Mycompany\Bannerslider\Model\ResourceModel\Banner');
        }
}
Related Topic