浏览文章
文章信息
Compilation was started.
Interception cache generation... 6/8 [=====================>------] 75% 47 secs 324.0 MiBErrors during compilation:
Aiweline\CustomerMessage\Model\ResourceModel\Message\DataProvider
Incompatible argument type: Required type: string. Actual type: \Aiweline\CustomerMessage\Model\ResourceModel\Message\name; File:
原因:
以下代码中的析构函数
/**
* DataProvider 初始函数...
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param array $meta
* @param array $data
* @param \Magento\Framework\App\RequestInterface $request
* @param \Aiweline\CustomerMessage\Model\MessageFactory $messageFactory
*/必须给定参数类型:例如@param string $name
@param string $name否则将得到这种错误
/**
* DataProvider 初始函数...
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param array $meta
* @param array $data
* @param \Magento\Framework\App\RequestInterface $request
* @param \Aiweline\CustomerMessage\Model\MessageFactory $messageFactory
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
\Magento\Framework\App\RequestInterface $request,
\Aiweline\CustomerMessage\Model\MessageFactory $messageFactory,
array $meta = [],
array $data = []
) {
$this->messageFactory = $messageFactory;
$this->request = $request;
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
}
解决:
参考父类\Magento\Ui\DataProvider\AbstractDataProvider
/**
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param array $meta
* @param array $data
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
array $meta = [],
array $data = []
) {
$this->name = $name;
$this->primaryFieldName = $primaryFieldName;
$this->requestFieldName = $requestFieldName;
$this->meta = $meta;
$this->data = $data;
}接下来注意了:
将参数类型补上,执行第一次di报以下错不用管
bin/magento setup:di:compile
报错不用管:这是因为上次错误留下的残余文件导致di不能再次执行,第二次执行会清空
PHP Fatal error: Uncaught Error: Cannot instantiate interface Symfony\Component\Console\Output\OutputInterface in /www/wwwroot/nyif.us/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:121
Stack trace:
......
接着再执行一次di即可
bin/magento setup:di:compile