1

According to coding standard protected function should not be used, so i have changed from protected to public then,

I am getting this warning from coding standard,

Warning: The use of public non-interface method in ACTION is discouraged.

The code is,

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

I changed to

public function _isAllowed()
{
    return $this->_authorization->isAllowed('frontname_namespace::orders');
}

Anyone have any idea about this ..

2 Answers 2

0

Supposing you are talking about a class inheriting from "\Magento\Backend\App\Action", you should delare it as protected, since you are extending a class that declares it as protected (see: \Magento\Backend\App\AbstractAction).

In this case you should ignore the "protected discouraged" message since is a Magento core class using it.

If you are going to create a new class not inheriting from any other Magento core class, then you should always follow the rule "private over protected", since class extension is disencouraged and, in that case, class composition is the right way.

4
  • yes, i am extending \Magento\Backend\App\Action this class.according to coding standard we should not use protected function.so i have found another way to declare that function. now its working fine. i just used acl.xml Commented Feb 3, 2018 at 11:37
  • You should avoid using protected methods only when you can. If you are extending a Magento core class, sometimes you must use it. Commented Feb 3, 2018 at 11:55
  • @chris, How did you solve this issue? You said that you found another way to declare that function. How did you declare that function? Commented Jun 21, 2018 at 7:51
  • @DineshYadav use acl.xml Commented Jul 5, 2018 at 7:41
0

create the file acl.xml inside /var/wwww/html/magento2/Module/Name/etc/acl.xml.

<?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
        <acl>
            <resources>
                <resource id="Magento_Backend::admin">
                    <resource id="Module_Name::orders" title="Orders" sortOrder="51">
            </resource>
                    </resource>
                </resource>
            </resources>
        </acl>
    </config>

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.