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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.