I have been struggling with a problem for a while and hope somebody can point me in the right direction.
I am attempting to extend a native controller by adding my own module. This appears to have worked successfully in the most part. I now have a need to call a bespoke model as an additional parameter in my overriding controllers constructor.
When I attempt to add the new parameter, I am met with the following error:
Uncaught ArgumentCountError: Too few arguments to function Companyname\Modulename\Controller\Result\Index::__construct(), 5 passed in
Here is my code for my working controller as an example:
namespace Companyname\Modulename\Controller\Result;
use Magento\Catalog\Model\Layer\Resolver;
use Magento\Catalog\Model\Session;
use Magento\Framework\App\Action\Context;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Search\Model\QueryFactory;
class Index extends \Magento\CatalogSearch\Controller\Result\Index
{
protected $layerResolver;
protected $_queryFactory;
public function __construct(
Context $context,
Session $catalogSession,
StoreManagerInterface $storeManager,
QueryFactory $queryFactory,
Resolver $layerResolver,
) {
parent::__construct(
$context,
$catalogSession,
$storeManager,
$queryFactory,
$layerResolver,
$customer
);
$this->layerResolver = $layerResolver;
$this->_queryFactory = $queryFactory;
}
public function execute()
{
$this->layerResolver->create(Resolver::CATALOG_LAYER_SEARCH);
$query = $this->_queryFactory->get();
// more code
}
}
Maybe I am going about this is completely the wrong way. if somebody could give me a few pointers I'd appreciate it.