0

Error:

Fatal error:

Method Magento\Ui\TemplateEngine\Xhtml\Result::__toString() must not throw an exception, caught TypeError: Argument 5 passed to Sparx\Drm\Model\ResourceModel\Grid\Collection\Interceptor::__construct() must implement interface Magento\Framework\DB\Adapter\AdapterInterface, string given, called in /home/bargaink/public_html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 93 in /home/bargaink/public_html/vendor/magento/module-ui/Component/Wrapper/UiComponent.php on line 0

When i removed var/di error removed. But when i again run bin/magento setup:di:compile i got same error.

magento version 2.1.7

Here is the file:

<?php 
namespace Sparx\Drm\Model\ResourceModel\Grid;

class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
    /**
     * Define resource model
     *
     * @return void
     */
    // protected function _construct()
    // {
    //     $this->_init('Sparx\Drm\Model\Drm', 'Sparx\Drm\Model\ResourceModel\Drm');
    // }


    protected $_idFieldName = 'id';

    protected $_storeManager;

    public function __construct(
        \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory,
        \Psr\Log\LoggerInterface $logger,
        \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
        \Magento\Framework\Event\ManagerInterface $eventManager,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
        \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
    ) {
        parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
        $this->_storeManager = $storeManager;
    }

    protected function _construct()
    {
        $this->_init('Sparx\Drm\Model\Drm','Sparx\Drm\Model\ResourceModel\Drm');
        $this->_map['fields']['entity_id'] = 'main_table.id';
    }

}

Is there something wrong with the coding?

Thanks

  • If parameters are not passed as expected order and proper then it is giving error while di:compile – Pramod Kharade Jan 11 '18 at 2:26
0

Replace __construct function with following code :

public function __construct(
    \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory,
    \Psr\Log\LoggerInterface $logger,
    \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
    \Magento\Framework\Event\ManagerInterface $eventManager,
    \Magento\Store\Model\StoreManagerInterface $storeManager

) {
    parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection = null, $resource = null);
    $this->_storeManager = $storeManager;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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