Magento – Error While Compiling Magento 2 admin page module

admin-controllercompilationmagento2

I'm getting error while compiling the Magento 2 admin module. The error which I'm getting is

Fatal error: Class Tutorial\SimpleNews\Controller\Adminhtml\News
contains 1 abstract method and must therefore be declared abstract or
implement the remaining methods
(Magento\Framework\App\ActionInterface::execute) in
/Applications/XAMPP/xamppfiles/htdocs/MagentoTest/app/code/Tutorial/SimpleNews/Controller/Adminhtml/News.php
on line 60

Here is my code:

    <?php

namespace Tutorial\SimpleNews\Controller\Adminhtml;

use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Registry;
use Magento\Framework\View\Result\PageFactory;
use Tutorial\SimpleNews\Model\NewsFactory;

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

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

    /**
     * News model factory
     *
     * @var \Tutorial\SimpleNews\Model\NewsFactory
     */
    protected $_newsFactory;

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

    /**
     * News access rights checking
     *
     * @return bool
     */
    protected function _isAllowed()
    {
        return $this->_authorization->isAllowed('Tutorial_SimpleNews::manage_news');
    }
}

Best Answer

Yes.. you need to add the execute method in the controller action..eg:-

public function execute() {

    $this->resultPage = $this->resultPageFactory->create();
    $this->resultPage->setActiveMenu('Tutorial_SimpleNews::manage');
    return $this->resultPage;       
}
Related Topic