1

I'm trying to create a tab within the customer section of admin by following this tutorial: http://www.ibnab.com/en/blog/magento-2/magento-2-backend-create-custom-tab-in-customer-view-and-load-grid-inside-admin.

When i try to reach my controller:

PHP Fatal error:  Uncaught TypeError: Argument 2 passed to Magento\\Customer\\Controller\\Adminhtml\\Index::__construct() must be an instance of Magento\\Framework\\Registry, none given, called in /var/www/mage2/public_html/generated/code/Vendor/Module/Controller/Adminhtml/Index/Index/Interceptor.php on line 14

I have a basic controller working however using the above tutorials controller i get that error when extending the controller to use the \Magento\Customer\Controller\Adminhtml\Index class. I have tried clearing di and generation folders but the error persists.

Basic Working Controller:

namespace Vendor\Module\Controller\Adminhtml\Index;

use Magento\Backend\App\Action;
use Magento\TestFramework\ErrorLog\Logger;

class Index extends \Magento\Backend\App\Action
{
    public function execute()
    {

        $this->_view->loadLayout();
        $this->_view->getLayout()->initMessages();
        $this->_view->renderLayout();
    }
}

This controller doesn't work:

namespace Vendor\Module\Controller\Adminhtml\Index;

use Magento\Backend\App\Action;
use Magento\TestFramework\ErrorLog\Logger;

class Index extends \Magento\Customer\Controller\Adminhtml\Index
{

     * Customer compare grid
     *
     * @return \Magento\Framework\View\Result\Layout

    public function execute()
    {
        $this->initCurrentCustomer();
        $resultLayout = $this->resultLayoutFactory->create();
        return $resultLayout;
    }
}

As previously stated it seems to break when changing the class that the controller is extending.

  • your version is magento 2.2? – Rakesh Jesadiya Dec 1 '17 at 10:50
  • Yeah sorry 2.2.1 – harri Dec 1 '17 at 10:51
  • 1
    Did you remove generation and var folder from root? – Rakesh Jesadiya Dec 1 '17 at 10:52
  • I cleared var/generation/* var/di/* – harri Dec 1 '17 at 10:53
  • in root generated folder exitst please remove it not var/generation – Rakesh Jesadiya Dec 1 '17 at 10:54
5

Whenever you declare dependency injection class in your constructor for php file for creating module,

For Magento 2.0.* and 2.1.*

You must need to remove var/generation folder content 

For Magento 2.2.*

You must need to remove var folder and generated folder content except .htacess file from root.

Now you can check your module no any inception generated file error shown.

| improve this answer | |
  • So this has changed since the 2.2.x release? – harri Dec 1 '17 at 11:28
  • Yes since 2.2.x new generated folder are available in root for interception/factory class – Rakesh Jesadiya Dec 1 '17 at 11:29
  • ah yeah i thought something was up as could always fix the error clearing them old folders. Cheers for this – harri Dec 1 '17 at 11:30
0

I had the same issue and resolving it by following steps

First, you need to remove generated/code/* and var/cache/*

rm -rf generated/code/* var/cache/*

Second, Clean the cache

php bin/magento cache:clean

Third, Change the file permission

sudo chmod 777 -R generated/ var/ pub/

Fourth, run Generated Compile the code

php bin/magento setup:di:compile
| improve this answer | |

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.