Return a list of Selected Option from a Select Attribute
Permalink 1 user found helpful
I'm building a custom block that returns images as well as information about them from some custom attributes. The basic text attributes are easy enough to get the values for, but getting the selected values from a select type attribute seems like a nightmare.
I've tried Jordan Lev's code from here:
http://www.concrete5.org/community/forums/customizing_c5/get-page-t...
It throws a fatal error at this line:
"Fatal Error: Call to a member function getAttributeKeyID() on a non-object"
I've checked my attribute handle and it is correct.
After looking through the Docs, I changed getOptions to getSelectedOptions, which gets rid of the error, but does not return any values. I've made sure there are selected option on the files and all, but getSelectedOptions still returns empty.
I'm running 5.5.2
I've tried Jordan Lev's code from here:
http://www.concrete5.org/community/forums/customizing_c5/get-page-t...
Loader::model('attribute/type'); Loader::model('attribute/categories/collection'); $ak = CollectionAttributeKey::getByHandle('your_attribute_handle'); $satc = new SelectAttributeTypeController(AttributeType::getByHandle('select')); $satc->setAttributeKey($ak); $values = $satc->getOptions(); foreach ($values as $v) { echo 'ID: ' . $v->ID; echo 'Value: ' . $v->value; }
It throws a fatal error at this line:
$values = $satc->getOptions();
"Fatal Error: Call to a member function getAttributeKeyID() on a non-object"
I've checked my attribute handle and it is correct.
After looking through the Docs, I changed getOptions to getSelectedOptions, which gets rid of the error, but does not return any values. I've made sure there are selected option on the files and all, but getSelectedOptions still returns empty.
I'm running 5.5.2
You should check if $ak returns an object.
if(is_object($ak)){
//rest of code
}
If it doesn't return an object, double check if the handle and whether the attribute is an 'Collection' attribute.