Cannot find my custom page attributes in controller

Permalink
Hi,
I have set up a controller, passed it a page(collection)ID and successfully loaded the page object, which contains the usual default stuff- title, version, url etc.

I have some custom attributes I have created, however the attributes section of the page object (when printed as an array) is empty......???!

Where are my attributes, how do I access them? $page->getAttribute($akHandle) isn't working for me.

My page attributes seem to be working fine -in that they are displayed in composer, saving data fine- and have been added to the page view and the page list no worries..

I have been searching the docs and still confused, can't see what I am missing- Please help!

class CartController extends Controller {
      public function add_to_cart() {
         //Read in the product to be added..
         $prdCID = $this->post('prdCID');
         $this->set('prdCID', $prdCID);
         $productInfo = $this->get_product($prdCID);
         print_r($productInfo);
       }
      protected function get_product($productCollectionID){
         $product = array();         
         $product['id'] = $productCollectionID;
         $prdPageObj = Page::getByID($productCollectionID, $version = 'active');
         $product['name'] = $prdPageObj->getCollectionName();            
         $product['thumbnail'] = $prdPageObj->getAttribute('product_thumbnail');         
         $product['price'] = $prdPageObj->getAttribute('product_price');

 
bbeng89 replied on at Permalink Reply
bbeng89
I'm not positive, but I think the $version variable might need to be capital. So:
$prdPageObj = Page::getByID($productCollectionID, $version = 'ACTIVE');


If that doesn't help, then out of curioustiy, do you get the same results if you leave the $version = 'active' bit out when you retrieve the page? So
$prdPageObj = Page::getByID($productCollectionID);
katiam replied on at Permalink Reply
Thank you, that's spot on- didn't realise it was case sensitive. Knew it would be something obvious, thx again!
Benji replied on at Permalink Best Answer Reply
Benji
Right, like bbeng89 said, the version actually MUST be in caps, but also you don't need the $version = part. This works just fine:
$prdPageObj = Page::getByID($productCollectionID, 'ACTIVE');


If you still can't get anything out of $page->getAttribute($akHandle), then you might want to check that your 'ACTIVE' version does indeed have those attributes. The active version is the one that is "published", and if you've filled in the attributes since the time you last published, they might only be showing in the 'RECENT' version that you're seeing as the logged-in page owner/editor.

Hope that helps,
Benji
katiam replied on at Permalink Reply
Thank you, the case sensitivity was the issue.
I checked the version and it was active.. weird thing is the attributes weren't loaded when the page object was set up and loaded, it loads an empty attributes array which seems odd, makes sense to reduce overheads... but confused me.