Concrete5.7.5.2 - topic list getTopicLink() - “illegal offset type” error

Could anyone please tell me why if I get a topic link and use it in a select option this way:
echo '<select id="regions" name="regions" class="form-control">';
echo '<option value="' . $view->controller->getTopicLink($region) . '">' . $region->getTreeNodeDisplayName() . '</option>';
echo '</select>';

it all works fine. But if I use it this way:
$regions[$view->controller->getTopicLink($region)] = $region->getTreeNodeDisplayName();
echo $form->select('regions', $regions);

it gives me an "illegal offset type" error?

And second question - there is a topic list block which shows topic links as link elements <a>, where it filters pages by topics when clicked on the links. But how can I do the same filtering if I want to have the topic list as a selectbox element? So when I select an option from the select box, it should filter the pages as the default one does.

Thank you.

View Replies:
jero replied on at Permalink Reply
$regions[ (string) $view->controller->getTopicLink($region)] =$region->getTreeNodeDisplayName();

Most likely getTopicLink is returning an object. In the simple case of echo, you're getting the right thing happen because the magic __toString() method is being run. In the other case, it's not because you're making an assignment, thus you're trying to use an object as an array index which is illegal hence the warning. Casting to string ensures you're using string data as the array index.