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);
}
}
var/generation
folder?