like this:
<?php namespace Apriljune\Testimonial\Controller\Adminhtml\Testimonial; use Exception; use Magento\Backend\App\Action; use Magento\Framework\Controller\ResultFactory; use Magento\Backend\App\Action\Context; use Apriljune\Testimonial\Model\ResourceModel\Testimonial\Collection as Testimonial; /** * Class MassDelete * * @package Apriljune\Testimonial\Controller\Adminhtml\Testimonial */ class MassDelete extends Action { /** * @var Testimonial */ protected $testimonial; /** * @param Context $context * @param Testimonial $testimonial */ public function __construct( Context $context, Testimonial $testimonial ) { parent::__construct($context); $this->testimonial = $testimonial; } /** * Execute action * * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { $selectedIds = $this->getRequest()->getParams()['selected']; if (!is_array($selectedIds)) { $this->messageManager->addErrorMessage(__('Please select one or more testimonial.')); } else { try { $collectionSize = count($selectedIds); foreach ($selectedIds as $_id) { $testimonial = $this->testimonial->getItems()[$_id]; $testimonial->delete(); } $this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been deleted.', $collectionSize)); } catch (Exception $e) { $this->messageManager->addErrorMessage($e->getMessage()); } } /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $resultRedirect->setPath('*/*/'); } }
and massaction is like this in ui-component
<massaction name="listing_massaction"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="component" xsi:type="string">Magento_Ui/js/grid/tree-massactions</item> </item> </argument> <action name="delete"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="type" xsi:type="string">delete</item> <item name="label" xsi:type="string" translate="true">Delete</item> <item name="url" xsi:type="url" path="*/*/MassDelete"/> <item name="confirm" xsi:type="array"> <item name="title" xsi:type="string" translate="true">Delete</item> <item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete selected items?</item> </item> </item> </argument> </action> </massaction>
Now when i select any row and delete it it redirect to the error page and show the exception
Type Error occurred when creating object: Apriljune\Testimonial\Controller\Adminhtml\Testimonial\MassDelete\Interceptor
i have already tried the solutions,
already done with this process as well
rm -rf var/di/* pub/static/* generated/* rm -rf var/cache/* var/view_preprocessed/* bin/magento setup:upgrade bin/magento setup:di:compile bin/magento setup:static-content:deploy bin/magento cache:flush
Interceptor is already create in /generated i have checked it.
But still the error is there any hint why it is showing error? any typo or logical error? BTW i am using 2.3.3 version of Magento