1

This has been asked a few times I know and I studied all of them and I also get the ieda what went wrong. However I cannot adapt those solutions to my issue.

I have a Class Post which extends \Magento\Backend\App\Action:

namespace Vendor\Module\Controller\Adminhtml;

abstract class Post extends \Magento\Backend\App\Action { ...

And I have a class Save that extends this \Vendor\Module\Controller\Adminhtml\Post:

namespace Vendor\Module\Controller\Adminhtml\Post;

class Save extends \Vendor\Module\Controller\Adminhtml\Post { ...

Class Post has the following __construct():

public function __construct(
        \Vendor\Module\Model\PostFactory $postFactory,
        \Magento\Framework\Registry $coreRegistry,
        \Magento\Backend\App\Action\Context $context
    )
    {
        $this->_postFactory           = $postFactory;
        $this->_coreRegistry          = $coreRegistry;
        parent::__construct($context);
    }

Class Save has the following __construct():

public function __construct(
    \Vendor\Module\Model\Upload $uploadModel,
    \Vendor\Module\Model\Post\File $fileModel,
    \Vendor\Module\Model\Post\Image $imageModel,
    \Vendor\Module\Model\PostFactory $postFactory,
    \Magento\Framework\Registry $registry,
    \Magento\Backend\App\Action\Context $context
)
{
    $this->_uploadModel    = $uploadModel;
    $this->_fileModel      = $fileModel;
    $this->_imageModel     = $imageModel;
    $this->_backendSession = $context->getSession();
    parent::__construct($postFactory, $registry, $context);
}

As far as I understand, the Post Class takes 3 Parameters in construct and I provide 3 Parameters to parent construct in Save Class. However when I execute setup:di:compile, I get the following error:

Vendor\Module\Controller\Adminhtml\Post\Save
        Extra parameters passed to parent construct: $context. File: /html/magento2/app/code/Vendor/Module/Controller/Adminhtml/Post/Save.php

Why is this happening and how can I fix this? I have been trying for hours, but I can't get rid of it...

The following is one of the threads I found, but like I said I can't adapt this on my own: Error : Extra parameters passed to parent construct: $coreRegistry

NOTE: Of course I created the needed protected variables accordingly, so there is no issue here.

  • Any chance you have something older in your generated folder? – David Manners Jun 2 '17 at 9:12
  • No, I already checked it 100 times... I am totally frustrated ... – hallleron Jun 2 '17 at 9:23
  • odd. It should not matter but what if you put the context first in the method declaration in both your Post and Save classes. – David Manners Jun 2 '17 at 10:03
  • Well I tried it, but now I have a blank page and when compiling I get: Vendor\Module\Controller\Adminhtml\Post\Save Incompatible argument type: Required type: \Magento\Backend\App\Action\Context. Actual type: \Vendor\Module\Model\PostFactory; File: /html/magento2/app/code/Vendor/Module/Controller/Adminhtml/Post/Save.php – hallleron Jun 2 '17 at 12:55
  • did you also change the order of the parameters in the parent::__construct($postFactory, $registry, $context); call? – David Manners Jun 2 '17 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.