0

Fatal error: Uncaught TypeError: Argument 2 passed to Mageplaza\HelloWorld\Controller\Adminhtml\Post\MassDelete::__construct() must be an instance of Magento\Ui\Component\MassAction\Filter, instance of Magento\Framework\View\Result\PageFactory given, called in E:\xampp\htdocs\mage\generated\code\Mageplaza\HelloWorld\Controller\Adminhtml\Post\massDelete\Interceptor.php on line 14 and defined in E:\xampp\htdocs\mage\app\code\Mageplaza\HelloWorld\Controller\Adminhtml\Post\MassDelete.php:27 Stack trace: #0 E:\xampp\htdocs\mage\generated\code\Mageplaza\HelloWorld\Controller\Adminhtml\Post\massDelete\Interceptor.php(14): Mageplaza\HelloWorld\Controller\Adminhtml\Post\MassDelete->__construct(Object(Magento\Backend\App\Action\Context), Object(Magento\Framework\View\Result\PageFactory)) #1 E:\xampp\htdocs\mage\vendor\magento\framework\ObjectManager\Factory\AbstractFactory.php(111): Mageplaza\HelloWorld\Controller\Adminhtml\Post\massDelete\Interceptor->__construct(Object(Magento\Backend\App\Action\Context), Object(Magento\Framework in E:\xampp\htdocs\mage\app\code\Mageplaza\HelloWorld\Controller\Adminhtml\Post\MassDelete.php on line 27

E:\xampp\htdocs\mage\app\code\Mageplaza\HelloWorld\Model\ResourceModel\Post.php

namespace Mageplaza\HelloWorld\Model\ResourceModel;


class Post extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{

    public function __construct(
        \Magento\Framework\Model\ResourceModel\Db\Context $context
    )
    {
        parent::__construct($context);
    }

    protected function _construct()
    {
        $this->_init('api_data', 'id');
    }

}

E:\xampp\htdocs\mage\app\code\Mageplaza\HelloWorld\Model\ResourceModel\Post\Colection.php

namespace Mageplaza\HelloWorld\Model\ResourceModel\Post;

class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
    protected $_idFieldName = 'id';
    protected $_eventPrefix = 'mageplaza_helloworld_post_collection';
    protected $_eventObject = 'post_collection';

    /**
     * Define resource model
     *
     * @return void
     */
    protected function _construct()
    {
        $this->_init('Mageplaza\HelloWorld\Model\Post', 'Mageplaza\HelloWorld\Model\ResourceModel\Post');
    }

}

E:\xampp\htdocs\mage\app\code\Mageplaza\HelloWorld\Controller\Adminhtml\Post\MassDelete.php

namespace Mageplaza\HelloWorld\Controller\Adminhtml\Post;


use Magento\Backend\App\Action\Context;
use Magento\Ui\Component\MassAction\Filter;
use Mageplaza\HelloWorld\Model\ResourceModel\Post\CollectionFactory;
use Magento\Framework\Controller\ResultFactory;
/**
 * Class MassDisable
 */
class MassDelete  extends \Magento\Backend\App\Action
{
    /**
     * @var Filter
     */
    protected $filter;
    /**
     * @var CollectionFactory
     */
    protected $collectionFactory;
    /**
     * @param Context $context
     * @param Filter $filter
     * @param CollectionFactory $collectionFactory
     */
    public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory)
    {
        $this->filter = $filter;
        $this->collectionFactory = $collectionFactory;
        parent::__construct($context);
    }
    /**
     * Execute action
     *
     * @return \Magento\Backend\Model\View\Result\Redirect
     * @throws \Magento\Framework\Exception\LocalizedException|\Exception
     */
    public function execute()
    {
        $collection = $this->filter->getCollection($this->collectionFactory->create());
        $collectionSize = $collection->getSize();
        foreach ($collection as $item) {
            $item->delete();
        }
        $this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $collectionSize));
        /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
        $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
        return $resultRedirect->setPath('*/*/');
    }
}

E:\xampp\htdocs\mage\app\code\Mageplaza\HelloWorld\Controller\Adminhtml\Post\Delete.php

namespace Mageplaza\HelloWorld\Controller\Adminhtml\Post;
use Magento\Backend\App\Action;
use Magento\TestFramework\ErrorLog\Logger;
class Delete extends \Magento\Backend\App\Action
{
    /**
     * {@inheritdoc}
     */
    protected function _isAllowed()
    {
        return $this->_authorization->isAllowed('Mageplaza_HelloWorld::delete');
    }
    /**
     * Delete action
     *
     * @return \Magento\Framework\Controller\ResultInterface
     */
    public function execute()
    {
        $id = $this->getRequest()->getParam('id');
        /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
        $resultRedirect = $this->resultRedirectFactory->create();
        if ($id) {
            try {
                $model = $this->_objectManager->create('Mageplaza\HelloWorld\Model\Post');
                $model->load($id);
                $model->delete();
                $this->messageManager->addSuccess(__('The post has been deleted.'));
                return $resultRedirect->setPath('*/*/');
            } catch (\Exception $e) {
                $this->messageManager->addError($e->getMessage());
                return $resultRedirect->setPath('*/*/edit', ['post_id' => $id]);
            }
        }
        $this->messageManager->addError(__('We can\'t find a post to delete.'));
        return $resultRedirect->setPath('*/*/');
    }
}
1
  • You have to do di compile again but before do it please delete file and folder from generate/code and generate/metadata
    – Amit Bera
    Commented Sep 5, 2018 at 7:16

1 Answer 1

1

Uncaught TypeError: Argument X passed to __construct()

These errors are generating when you have injected/remove a new classes to __construct() function. But did not do di compile

So,You have to do di compile again but before do it please delete file and folder from generate/code and generate/metadata

1
  • I got similar error after doing di compile. Commented Oct 28, 2019 at 10:11

Your Answer

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

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