0

Hi I have problem in Define model constructor, This is my code:

<?php namespace Retailers\Company\Model\Category; use \Magento\Framework\Option\ArrayInterface; class CategoryList implements ArrayInterface { protected $_categoryCollectionFactory; public function __construct( \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $collectionFactory, array $data = [] ) { $this->_categoryCollectionFactory = $collectionFactory; } public function toOptionArray($addEmpty = true) { /** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $collection */ $collection = $this->_categoryCollectionFactory->create(); $collection->addAttributeToSelect('name');//->addRootLevelFilter()->load(); $options = []; if ($addEmpty) { $options[] = ['label' => __('-- Please Select a Category --'), 'value' => '']; } foreach ($collection as $category) { $options[] = ['label' => $category->getName(), 'value' => $category->getId()]; } return $options; } } 
1
  • You probably need to recompile DI. Please post full exception. Commented Nov 6, 2017 at 14:03

1 Answer 1

1

Just clear your cache and remove the generation/di folders.

  • cd /path/to/magento2
  • rm -rf var/cache var/page_cache
  • rm -rf var/generation var/di

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.