Saving Select Attributes with API

Permalink
Hi, I've been adding all the attributes from an attribute set to a single page like this:

$atSet = AttributeSet::getByHandle('attribute_set_handle');
$atKeys = $atSet->getAttributeKeys();
    foreach($atKeys as $ak) {
        echo $atkey->render('label', t($ak->akName));
   echo $atkey->render('form', $value ,true);
    }


and then on the single page controller I have been saving those attribute like this:

$atSet = AttributeSet::getByHandle('attribute_set_handle');
$atKeys = $atSet->getAttributeKeys();
    foreach($atKeys as $ak) {
        $ak = CollectionAttributeKey::getByHandle($ak->akHandle);
   $ak->saveAttributeForm($page);          
    }


This is working fine for all attribute types except for Select Attributes, like the Tags attribute, the selected values do not get saved to the page. Anyone know why the select values do not save when you do it this way?

thanks

pvernaglia
 
Mainio replied on at Permalink Reply
Mainio
Coparing this to the core code in /concrete/startup/process.php

I don't see anything else different here than saving the attribute on the page object instead of the page version object.

This is how it's done in core (modified to fit your code above):
$nvc = $page->getVersionToModify();
foreach($atKeys as $ak) {
  $ak->saveAttributeForm($nvc);
}


Don't know if this is the reason but maybe worth to try...?