I have a CRUD module created on magento 2.1.6 version which was working ok untill i updated magento to version 2.2.1
Now when i compile my code i receive the following err:
namespace\module\Model\ResourceModel\Post\Grid\Collection
Incompatible argument type: Required type: \Magento\Framework\DB\Adapter\AdapterInterface. Actual type: \namespace\module\Model\ResourceModel\Post\Grid\connection; File:
/data/web/public/app/code/namespace/module/Model/ResourceModel/Post/Grid/Collection.php
so my constructor looks like this before i made any changes:
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,
$mainTable,
$eventPrefix,
$eventObject,
$resourceModel,
$model = 'Magento\Framework\View\Element\UiComponent\DataProvider\Document',
$connection = null,
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
)
{
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
$this->_eventPrefix = $eventPrefix;
$this->_eventObject = $eventObject;
$this->_init($model, $resourceModel);
$this->setMainTable($mainTable);
}
after i changed the constructor according to the compile error my constructor looks like this:
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\Framework\DB\Adapter\AdapterInterface $connection = null,
$mainTable,
$eventPrefix,
$eventObject,
$resourceModel,
$model = 'Magento\Framework\View\Element\UiComponent\DataProvider\Document',
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
)
{
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
$this->_eventPrefix = $eventPrefix;
$this->_eventObject = $eventObject;
$this->_init($model, $resourceModel);
$this->setMainTable($mainTable);
}
Now when i compile the code i don't have any err, but when i tried to access my "module menu" i receive this err:
PHP message: PHP Fatal error: Method Magento\Ui\TemplateEngine\Xhtml\Result::__toString() must not throw an exception, caught Error: Cannot instantiate interface Magento\Framework\DB\Adapter\AdapterInterface
IT said that "Magento\Framework\DB\Adapter\AdapterInterface" can't be instantiate, even the compile was asking for this.
Does anyone have any idea how to solve this problem?