2

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 /home/dukaania/public_html/testing2/app/code/Tutorial/SimpleNews/Controller/Adminhtml/News.php on line 11

Here's my code:

/home1/dukaania/public_html/testing2/app/code/Tutorial/SimpleNews/Controller/Adminhtml/News.php

    <?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');
}



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

return $resultPage;
}

}

/home1/dukaania/public_html/testing2/app/code/Tutorial/SimpleNews/Controller/Adminhtml/News/Index.php

   <?php

  namespace Tutorial\SimpleNews\Controller\Adminhtml\News;

   use Tutorial\SimpleNews\Controller\Adminhtml\News;

   class Index extends News
  {
/**
 * @return void
 */
   public function execute()
  {
  if ($this->getRequest()->getQuery('ajax')) {
        $this->_forward('grid');
        return;
    }

    /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
    $resultPage = $this->_resultPageFactory->create();
    $resultPage->setActiveMenu('Tutorial_SimpleNews::main_menu');
    $resultPage->getConfig()->getTitle()->prepend(__('Simple News'));

    return $resultPage;

} }

0

Please replace your file code with below one

/home1/dukaania/public_html/testing2/app/code/Tutorial/SimpleNews/Controller/Adminhtml/News.php

what your mistake is

you are extending action class Magento\Backend\App\Action but you have have to extend this Magento\Backend\App\Action\Action class

 <?php

 namespace Tutorial\SimpleNews\Controller\Adminhtml;

 use \Magento\Framework\App\Action\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;


      protected $_resultPageFactory;

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

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


 protected function _isAllowed()
     {
return $this->_authorization->isAllowed('Tutorial_SimpleNews::manage_news');
      }



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

  return $resultPage;
}
  • now they showing this error 1 exception(s): Exception #0 (RuntimeException): Class Tutorial\SimpleNews\Model\NewsFactory does not exist in [Tutorial\SimpleNews\Controller\Adminhtml\News\Index\Interceptor] – jhon jhon doe Sep 24 '18 at 6:54
  • please clear your generated folder and clear cache and clean – Rutvee Sojitra Sep 24 '18 at 6:55
  • php bin/magento cache:flush Clear cache with this command and still facing issue – jhon jhon doe Sep 24 '18 at 6:58
  • Have remove your generated folder? rm -rf generated/* (if magento version >2.2.2) or rm -rf var/generation/* – Rutvee Sojitra Sep 24 '18 at 6:59
  • Now another issue i faced Fatal error: Namespace declaration statement has to be the very first statement or after any declare call in the script – jhon jhon doe Sep 24 '18 at 7:14

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.