1

I'm trying to have a reference to a model factory to load an object on desire. I just added a parameter to the constructor, but it generates an error:
(The parent constructor doesn't have the parameter: "\Magento\Catalog\Model\CategoryFactory $categoryFactory")

1 exception(s): Exception #0 (Exception): Recoverable Error: Argument 5 passed to Amaj\MegaMenu\Block\Html\Topmenu::__construct() must be an instance of Magento\Catalog\Model\CategoryFactory, none given, called in D:\ProgramFiles\wamp64\www\parastoo\var\generation\Amaj\MegaMenu\Block\Html\Topmenu\Interceptor.php on line 14 and defined in D:\ProgramFiles\wamp64\www\parastoo\app\code\Amaj\MegaMenu\Block\Html\Topmenu.php on line 33

What am I doing wrong? please help

Source code:

<?php

namespace Amaj\MegaMenu\Block\Html;

use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\View\Element\Template;
use Magento\Framework\Data\TreeFactory;
use Magento\Framework\Data\Tree\Node;
use Magento\Framework\Data\Tree\NodeFactory;

/**
 * Html page top menu block
 */
class Topmenu extends \Magento\Theme\Block\Html\Topmenu
{

    protected $categoryFactory;


    /**
     * @param Template\Context $context
     * @param NodeFactory $nodeFactory
     * @param TreeFactory $treeFactory
     * @param array $data
     * @param \Magento\Catalog\Model\CategoryFactory $categoryFactory
     */
    public function __construct(
        Template\Context $context,
        NodeFactory $nodeFactory,
        TreeFactory $treeFactory,
        array $data = [],
        \Magento\Catalog\Model\CategoryFactory $categoryFactory
    ) {
        $this->categoryFactory = $categoryFactory;
        parent::__construct($context, $nodeFactory, $treeFactory, $data);
    }
}
  • 1
    Tried to remove var/generation folder? – Khoa TruongDinh Dec 1 '16 at 16:13
  • 1
    @Khoa TruongDinh: Thanks. That was the problem. If you make it an answer, I will accept it. – Pro-Magento Dec 1 '16 at 16:58
1

When developing a module, we should care about generation files under var/generation. Sometimes, we meet:

Recoverable Error: Argument passed to __construct() must be an instance of

We should remove var/generation folder.

|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.