I have created one custom attribute for Category with Multi select option.I am trying to get dynamic values from source file but first value only printing in multi select please give solution and check my code what i did wrong. `

    $school_model = $this->_modelCreateFactory->create();
    $data = $school_model->getCollection()->getData();
    $value1 = array();
    foreach ($data as $key => $value) {
          if(!empty($value['school_id']))
          {
            if ($this->_options === null) {
                $value1[$key]['school_id'] =  $value['school_id'];
                $value1[$key]['school_name'] = $value['school_name'];

                $this->_options =[  [
                                       'value' => $value1[$key]['school_id'],
                                       'label' => __($value1[$key]['school_name'])
                                    ]
                                 ];
            }
          }
        }

    return $this->_options;
}`
有帮助吗?

解决方案

form an array like this. It will work

// Added brands

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $collection = $objectManager->create('Vendor\Mysize\Model\Brand');
    $option = $collection->getCollection();
    $optionsArray =[];
    foreach($option as $optionValues) { 
          $optionsArray [] = [
            'label' =>  $optionValues,
            'value' => $optionValues
      ];
        }
        return $optionsArray;


}
许可以下: CC-BY-SA归因
scroll top