facing this issue:
Fatal error: Namespace declaration statement has to be the very first
statement or after any declare call in the script in
/home/dukaania/public_html/testing2/app/code/Tutorial/SimpleNews/Controller/Adminhtml/News.php
on line 3
Here's my code:
<?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;
}
}
Best Answer
without comment, you are not allowed to use any white space after the opening of PHP tag in the .php file in the Block folder. So remove white space or add /**/ to fix this issue which you are getting during the compilation