1

I can get into the execute() function if I do not run the construct function. but I cannot find the bug in my __construct function. The file is \app\code\Cleargo\Contactus\Controller\Adminhtml\Grid\Index.php

namespace Cleargo\Contactus\Controller\Adminhtml\Grid;

use Magento\Backend\App\Action;

class Index extends  Action

{
    const ADMIN_RESOURCE = 'Cleargo_Contactus::add_row';

protected $resultPageFactory;

public function __construct(
            \Magento\Backend\App\Action\Context $context,
            \Magento\Framework\View\Result\PageFactory $resultPageFactory
){
     parent::__construct($context);
    $this->resultPageFactory = $resultPageFactory;
}

public function execute()
{

    $resultPage = $this->resultPageFactory->create();
    $resultPage->getConfig()->getTitle()->prepend(__('Department'));

    return $resultPage;
}
}
1
  • 2
    the result of above code is a completely empty page
    – Yau Thomas
    Commented May 24, 2016 at 7:36

2 Answers 2

2

try same as above code,

namespace Cleargo\Contactus\Controller\Adminhtml\Grid;


class Index extends  \Magento\Backend\App\Action

{
    const ADMIN_RESOURCE = 'Cleargo_Contactus::add_row';

protected $resultPageFactory;

public function __construct(
            \Magento\Backend\App\Action\Context $context,
            \Magento\Framework\View\Result\PageFactory $resultPageFactory
){
     parent::__construct($context);
    $this->resultPageFactory = $resultPageFactory;
}

public function execute()
{

    $resultPage = $this->resultPageFactory->create();
    $resultPage->getConfig()->getTitle()->prepend(__('Department'));

    return $resultPage;
}
}

After adding same code and you must have to remove var folder from root and deploy command.

php bin/magento setup:static-content:deploy
3
  • it display an error : 'Class Cleargo\Contactus\Controller\Adminhtml\Grid\ \Magento\Backend\App\Action\Context does not exist'
    – Yau Thomas
    Commented May 24, 2016 at 9:47
  • i have updated my answer plz remove var folder and try again Commented May 24, 2016 at 10:03
  • it works! THX!!!
    – Yau Thomas
    Commented May 24, 2016 at 10:19
0

You need to add the _isAllowed method to your admin controller action to check the permissions to run it.

Assuming that your constant ADMIN_RESOURCE corresponds to the ACL resource you declared for this route, you should add the following code to your action class:

protected function _isAllowed()
{
    return $this->_authorization->isAllowed(self::ADMIN_RESOURCE);
}
2
  • 1
    it does not work for mine
    – Yau Thomas
    Commented May 24, 2016 at 7:54
  • protected function _isAllowed is already inherited from parent class
    – Ashish Raj
    Commented Aug 13, 2020 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.