Skip to main content
Tweeted twitter.com/StackMagento/status/1017121225372585986
format the error
Source Link
Manashvi Birla
  • 8.9k
  • 9
  • 28
  • 53

I've built an admin grid following a few tutorials and hit this error:

Warning: Invalid argument supplied for foreach() in /home/sadmin/mage/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php on line 253

Warning: Invalid argument supplied for foreach() in /home/sadmin/mage/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php on line 253

I went to the file and saw this function:

protected function searchResultToOutput(SearchResultInterface $searchResult)
{
    $arrItems = [];

    $arrItems['items'] = [];
    foreach ($searchResult->getItems() as $item) {
        $itemData = [];
        foreach ($item->getCustomAttributes() as $attribute) {
            $itemData[$attribute->getAttributeCode()] = $attribute->getValue();
        }
        $arrItems['items'][] = $itemData;
    }

    $arrItems['totalRecords'] = $searchResult->getTotalCount();

    return $arrItems;
}

for my data, there are no custom attributes, so how do I bypass this part of the function for my grid to load? Var_dumping my $searchResult->getItems() shows my table data so I'm not sure why this is needed, any help or explanations are much appreciated :)

Thanks!

I've built an admin grid following a few tutorials and hit this error:

Warning: Invalid argument supplied for foreach() in /home/sadmin/mage/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php on line 253

I went to the file and saw this function:

protected function searchResultToOutput(SearchResultInterface $searchResult)
{
    $arrItems = [];

    $arrItems['items'] = [];
    foreach ($searchResult->getItems() as $item) {
        $itemData = [];
        foreach ($item->getCustomAttributes() as $attribute) {
            $itemData[$attribute->getAttributeCode()] = $attribute->getValue();
        }
        $arrItems['items'][] = $itemData;
    }

    $arrItems['totalRecords'] = $searchResult->getTotalCount();

    return $arrItems;
}

for my data, there are no custom attributes, so how do I bypass this part of the function for my grid to load? Var_dumping my $searchResult->getItems() shows my table data so I'm not sure why this is needed, any help or explanations are much appreciated :)

Thanks!

I've built an admin grid following a few tutorials and hit this error:

Warning: Invalid argument supplied for foreach() in /home/sadmin/mage/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php on line 253

I went to the file and saw this function:

protected function searchResultToOutput(SearchResultInterface $searchResult)
{
    $arrItems = [];

    $arrItems['items'] = [];
    foreach ($searchResult->getItems() as $item) {
        $itemData = [];
        foreach ($item->getCustomAttributes() as $attribute) {
            $itemData[$attribute->getAttributeCode()] = $attribute->getValue();
        }
        $arrItems['items'][] = $itemData;
    }

    $arrItems['totalRecords'] = $searchResult->getTotalCount();

    return $arrItems;
}

for my data, there are no custom attributes, so how do I bypass this part of the function for my grid to load? Var_dumping my $searchResult->getItems() shows my table data so I'm not sure why this is needed, any help or explanations are much appreciated :)

Thanks!

Source Link
treyBake
  • 141
  • 1
  • 6
  • 27

Why does DataProvider (UiComponent) expect custom data to have custom attributes?

I've built an admin grid following a few tutorials and hit this error:

Warning: Invalid argument supplied for foreach() in /home/sadmin/mage/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php on line 253

I went to the file and saw this function:

protected function searchResultToOutput(SearchResultInterface $searchResult)
{
    $arrItems = [];

    $arrItems['items'] = [];
    foreach ($searchResult->getItems() as $item) {
        $itemData = [];
        foreach ($item->getCustomAttributes() as $attribute) {
            $itemData[$attribute->getAttributeCode()] = $attribute->getValue();
        }
        $arrItems['items'][] = $itemData;
    }

    $arrItems['totalRecords'] = $searchResult->getTotalCount();

    return $arrItems;
}

for my data, there are no custom attributes, so how do I bypass this part of the function for my grid to load? Var_dumping my $searchResult->getItems() shows my table data so I'm not sure why this is needed, any help or explanations are much appreciated :)

Thanks!