SinglePage - modify attribute in package controller

Permalink
I've been beating my head against this one for a while now. As far as I can tell, SinglePage::add is supposed to return a Page object. So is SinglePage::getByHandle - in theory.

I have a single page that I want to add in my package, and then set it to not appear in the auto-nav. So here's what's in my package controller:

FB::log('look for dd');
        $dd = SinglePage::getByHandle('division_display', $pkg);
        FB::log('dd is ', $dd);
        if (!is_object($dd)) {
            FB::log('adding');
            $mainPage = SinglePage::add('division_display', $pkg);
            FB::log('mp = ' . $mainPage);
            $mainPage->setAttribute('exclude_nav', 1 );
 // the above line yields error: Call to a member function setAttribute() on a non-object 
        }

Tried with both 1 and true in the setAttribute call - yeah, no difference in behavior.

FB = Firebug, and the console display is disheartening:
look for dd
dd is
adding
mp =


I cloned this from some code I found somewhere that does a similar test when installing a block. Clearly THAT was a bad idea, but damned if I can find what I should be doing instead.

Also, I found an unsettling comment in concrete/core/models/collection.php, which is where PHPStorm takes me if I highlight getByHandle and Go To > Declaration:
/* This function is slightly misnamed: it should be getOrCreateByHandle($handle) but I wanted to keep it brief

In 5.6.3.1 this is line 707. This is *probably* a red herring - but just in case...

TIA for any suggestions!

ssdscott
 
ssdscott replied on at Permalink Reply
ssdscott
Well, I gave up on the whole 'getByHandle' thing. I ended up using 'getByPath' since for a single page that's a reliable source for the Page object.