1

I have created a custom news module in Magento 2.

News module includes admin listing and edit.

But it is showing fatal error.

Fatal error: Class Namespace\Module\Controller\Adminhtml\Enquiry contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Magento\Framework\App\ActionInterface::execute)

My controller code is given below

<?php

namespace Namespace\Module\Controller\Adminhtml;

use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Registry;
use Magento\Framework\View\Result\PageFactory;
use Namespace\Module\Model\EnquiryFactory;

class Enquiry extends Action
{
    /**
     * Core registry
     *
     * @var \Magento\Framework\Registry
     */
    protected $_coreRegistry;

    /**
     * Result page factory
     *
     * @var \Magento\Framework\View\Result\PageFactory
     */
    protected $_resultPageFactory;

    /**
     * Enquiry model factory
     *
     * @var \Mbf\Enquries\Model\EnquiryFactory
     */
    protected $_enquiryFactory;

    /**
     * @param Context $context
     * @param Registry $coreRegistry
     * @param PageFactory $resultPageFactory
     * @param EnquiryFactory $enquiryFactory
     */
    public function __construct(
        Context $context,
        Registry $coreRegistry,
        PageFactory $resultPageFactory,
        EnquiryFactory $enquiryFactory
    ) {
       parent::__construct($context);
        $this->_coreRegistry = $coreRegistry;
        $this->_resultPageFactory = $resultPageFactory;
        $this->_enquiryFactory = $enquiryFactory;
    }

    /**
     * Enquiry access rights checking
     *
     * @return bool
     */
    protected function _isAllowed()
    {
        return $this->_authorization->isAllowed('Namespace_Module::manage_enquiry');
    }
}
1
  • I think you are missing execute() method in your controller. Oct 24, 2016 at 9:43

2 Answers 2

1

you were missing the execute() meth0d

public function execute()
    { 
        /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
        $resultPage = $this->resultPageFactory->create();
        $this->initPage($resultPage)->getConfig()->getTitle()->prepend(__('Spacename News'));
        return $resultPage;
    }
    protected function initPage($resultPage)
    {
        $resultPage->setActiveMenu('Spacename_Moduelname::news')
            ->addBreadcrumb(__('Spacename News'), __('News'))
            ->addBreadcrumb(__('Manage news'), __('Manage news'));
        return $resultPage;
    }
1

You need to provide an execute() method in your controller.

It depends on what you want to achieve.

A simple example could be:

public function execute()
{
    /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
    $resultPage = $this->_resultPageFactory->create();

    return $resultPage;
}

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.