i am getting this error while compiling,when i add dependency injection then getting other error like,filefactory if this solved then getting customerfactory. Actually i want to do custom code in my controller when user click - enter image description here

 namespace Vendor\Module\Controller\Adminhtml\Sendcredentials;
        use Magento\Backend\App\Action\Context;

    class Index extends  \Magento\Customer\Controller\Adminhtml\Index
         * Customer compare grid
         * @return \Magento\Framework\View\Result\Layout
       public function __construct(
            Context $context,
            array $data = [] 
        ) {
            parent::__construct($context, $data);


        public function execute()
            $resultLayout = $this->_resultLayoutFactory->create();
            $getBlock = $resultLayout->getLayout()->createBlock("Vendor\Module\Block\Adminhtml\Sendcredentials");
            echo $getBlock->getCustomCustomerId();



Actually i need customer id in my custom controller.

  • i edit question please check Apr 2, 2019 at 12:00
  • customer is already created,i just need to write my code in my controller file,when click on "send credentials" please refer image above Apr 2, 2019 at 12:17

2 Answers 2


You don't extend properly \Magento\Customer\Controller\Adminhtml\Index to your class when try to call __construct . If you check the code of then you find a lot of parameters need __construct:\Magento\Customer\Controller\Adminhtml\Index.


namespace Vendor\Module\Controller\Adminhtml\Sendcredentials;

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

    public function __construct(
            \Magento\Backend\App\Action\Context $context,
            \Magento\Framework\Registry $coreRegistry, 
            \Magento\Framework\App\Response\Http\FileFactory $fileFactory,
            \Magento\Customer\Model\CustomerFactory $customerFactory,
            \Magento\Customer\Model\AddressFactory $addressFactory,
            \Magento\Customer\Model\Metadata\FormFactory $formFactory, 
            \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory,
            \Magento\Customer\Helper\View $viewHelper, 
            \Magento\Framework\Math\Random $random, 
            \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
            \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter,
            \Magento\Customer\Model\Address\Mapper $addressMapper,
            \Magento\Customer\Api\AccountManagementInterface $customerAccountManagement,
            \Magento\Customer\Api\AddressRepositoryInterface $addressRepository,
            \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerDataFactory,
            \Magento\Customer\Api\Data\AddressInterfaceFactory $addressDataFactory,
            \Magento\Customer\Model\Customer\Mapper $customerMapper,
            \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor,
            \Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
            \Magento\Framework\DataObjectFactory $objectFactory,
            \Magento\Framework\View\LayoutFactory $layoutFactory,
            \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory,
            \Magento\Framework\View\Result\PageFactory $resultPageFactory,
            \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory,
            \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory) 
        parent::__construct($context, $coreRegistry, $fileFactory, $customerFactory, $addressFactory, $formFactory, $subscriberFactory, $viewHelper, $random, $customerRepository, $extensibleDataObjectConverter, $addressMapper, $customerAccountManagement, $addressRepository, $customerDataFactory, $addressDataFactory, $customerMapper, $dataObjectProcessor, $dataObjectHelper, $objectFactory, $layoutFactory, $resultLayoutFactory, $resultPageFactory, $resultForwardFactory, $resultJsonFactory);

    public function execute() {



No of parameters at __construct:\Magento\Customer\Controller\Adminhtml\Index is 25 ,https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Customer/Controller/Adminhtml/Index.php#L201-L225

but your extends class's has two parameters parent::__construct($context, $data) .So no of parameters should be same for extends __construct and original one.

  • but how to get customer id here ? Apr 2, 2019 at 12:27
  • $this->initCurrentCustomer(); provide you customer id
    – Amit Bera
    Apr 2, 2019 at 12:29
  • yes i already try this after your code but it show 0 Apr 2, 2019 at 12:31
  • What is the URL of button sendCrendtial?
    – Amit Bera
    Apr 2, 2019 at 12:32
  • localhost/projectname/admin/xxx/sendcredentials/index/customer_id/1/ Apr 2, 2019 at 12:33

Remove the constructor method from your class.
the original class Magento\Customer\Controller\Adminhtml\Index has a constructor with way more parameters than you provided in your code.

  • ok i will remove constructor class. but how may i get customer id here ? Apr 2, 2019 at 12:24
  • I am not able to get customer id Apr 2, 2019 at 12:40
  • you can send the id via GET from the button. How did you add the button in the page?
    – Marius
    Apr 2, 2019 at 13:36
  • 1
    thank you so much for your reply Upvote Apr 2, 2019 at 13:38

Your Answer

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

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